|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I want to include class in one php page. However I couldn't get it
working? I didn't get any error message but I didn't get the html page either. Any one could me? Thanks. <?php function __autoload($class) { if (file_exists($file = "$class.php")) { include($file); } else { throw new Exception("Class $class not found"); } } try { class_exists('pd'); $remo = new pd(); ?> <html> <head> </head> <body> <div id='div1'>test<br /> <?php print $remo.test(); print "sssssss"; } catch (Exception $e) { // Catch the exception and handle it as usual throw new Exception($e->getMessage()); } ?> </div> </body> </html> pd.php class pd{ private $dsn; function _pd() { $dsn = 'mysql://pd:password@127.0.0.1/pd'; } function test(){ return 2; } } |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Tue, 22 Jan 2008 19:41:01 +0100, <myzmlm@gmail.com> wrote:
> I want to include class in one php page. However I couldn't get it > working? I didn't get any error message but I didn't get the html page > either. Any one could me? Thanks. > > <?php > function __autoload($class) > { > if (file_exists($file = "$class.php")) > { > include($file); > } > else > { > throw new Exception("Class $class not found"); > } > } > > try > { > class_exists('pd'); What do you expect this does? > $remo = new pd(); > > ?> > <html> > <head> > </head> > <body> > <div id='div1'>test<br /> > <?php > print $remo.test(); $remo->test(); Be sure to enable display_error and set error_reporting to E_ALL | E_STRICT during development (in php.ini, httpd.conf or .htaccess). -- Rik Wasmus |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Jan 22, 1:54 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Tue, 22 Jan 2008 19:41:01 +0100, <myz...@gmail.com> wrote: > > I want to include class in one php page. However I couldn't get it > > working? I didn't get any error message but I didn't get the html page > > either. Any one could me? Thanks. > > > <?php > > function __autoload($class) > > { > > if (file_exists($file = "$class.php")) > > { > > include($file); > > } > > else > > { > > throw new Exception("Class $class not found"); > > } > > } > > > try > > { > > class_exists('pd'); > > What do you expect this does? > > > $remo = new pd(); > > > ?> > > <html> > > <head> > > </head> > > <body> > > <div id='div1'>test<br /> > > <?php > > print $remo.test(); > > $remo->test(); > > Be sure to enable display_error and set error_reporting to E_ALL | > E_STRICT during development (in php.ini, httpd.conf or .htaccess). > > -- > Rik Wasmus echo $remo->test() should output 2 on the web page. However I got a zero size output html file, which means there is something wrong with code. If I comment out the class part it will work without problem. I just can't figure out what's wrong with the class. I am using IIS6. I couldn't find display_error in php.ini. Thanks. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Tue, 22 Jan 2008 20:02:31 +0100, <myzmlm@gmail.com> wrote:
> On Jan 22, 1:54 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: >> On Tue, 22 Jan 2008 19:41:01 +0100, <myz...@gmail.com> wrote: >> > I want to include class in one php page. However I couldn't get it >> > working? I didn't get any error message but I didn't get the html page >> > either. Any one could me? Thanks. >> >> > <?php >> > function __autoload($class) >> > { >> > if (file_exists($file = "$class.php")) >> > { >> > include($file); >> > } >> > else >> > { >> > throw new Exception("Class $class not found"); >> > } >> > } >> >> > try >> > { >> > class_exists('pd'); >> >> What do you expect this does? >> >> > $remo = new pd(); >> >> > ?> >> > <html> >> > <head> >> > </head> >> > <body> >> > <div id='div1'>test<br /> >> > <?php >> > print $remo.test(); >> >> $remo->test(); >> >> Be sure to enable display_error and set error_reporting to E_ALL | >> E_STRICT during development (in php.ini, httpd.conf or .htaccess). >> > echo $remo->test() should output 2 on the web page. However I got a > zero size output html file, which means there is something wrong with > code. If I comment out the class part it will work without problem. I > just can't figure out what's wrong with the class. I am using IIS6. I > couldn't find display_error in php.ini. Just add: display_errors = 1 see also: http://nl2.php.net/manual/en/ref.errorfunc.php And, looking at it more closely, you seem to have forgotten the <?php ?> tags in your classfile. Adding those makes it work here. -- Rik Wasmus |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Jan 22, 2:08 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Tue, 22 Jan 2008 20:02:31 +0100, <myz...@gmail.com> wrote: > > On Jan 22, 1:54 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > >> On Tue, 22 Jan 2008 19:41:01 +0100, <myz...@gmail.com> wrote: > >> > I want to include class in one php page. However I couldn't get it > >> > working? I didn't get any error message but I didn't get the html page > >> > either. Any one could me? Thanks. > > >> > <?php > >> > function __autoload($class) > >> > { > >> > if (file_exists($file = "$class.php")) > >> > { > >> > include($file); > >> > } > >> > else > >> > { > >> > throw new Exception("Class $class not found"); > >> > } > >> > } > > >> > try > >> > { > >> > class_exists('pd'); > > >> What do you expect this does? > > >> > $remo = new pd(); > > >> > ?> > >> > <html> > >> > <head> > >> > </head> > >> > <body> > >> > <div id='div1'>test<br /> > >> > <?php > >> > print $remo.test(); > > >> $remo->test(); > > >> Be sure to enable display_error and set error_reporting to E_ALL | > >> E_STRICT during development (in php.ini, httpd.conf or .htaccess). > > > echo $remo->test() should output 2 on the web page. However I got a > > zero size output html file, which means there is something wrong with > > code. If I comment out the class part it will work without problem. I > > just can't figure out what's wrong with the class. I am using IIS6. I > > couldn't find display_error in php.ini. > > Just add: > display_errors = 1 > see also:http://nl2.php.net/manual/en/ref.errorfunc.php > > And, looking at it more closely, you seem to have forgotten the <?php ?> > tags in your classfile. Adding those makes it work here. > -- > Rik Wasmus Thanks. Find out it is stupid Windows related problem. Appreciate your . |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Jan 22, 2:16 pm, myz...@gmail.com wrote:
> On Jan 22, 2:08 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > > > > > On Tue, 22 Jan 2008 20:02:31 +0100, <myz...@gmail.com> wrote: > > > On Jan 22, 1:54 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > > >> On Tue, 22 Jan 2008 19:41:01 +0100, <myz...@gmail.com> wrote: > > >> > I want to include class in one php page. However I couldn't get it > > >> > working? I didn't get any error message but I didn't get the html page > > >> > either. Any one could me? Thanks. > > > >> > <?php > > >> > function __autoload($class) > > >> > { > > >> > if (file_exists($file = "$class.php")) > > >> > { > > >> > include($file); > > >> > } > > >> > else > > >> > { > > >> > throw new Exception("Class $class not found"); > > >> > } > > >> > } > > > >> > try > > >> > { > > >> > class_exists('pd'); > > > >> What do you expect this does? > > > >> > $remo = new pd(); > > > >> > ?> > > >> > <html> > > >> > <head> > > >> > </head> > > >> > <body> > > >> > <div id='div1'>test<br /> > > >> > <?php > > >> > print $remo.test(); > > > >> $remo->test(); > > > >> Be sure to enable display_error and set error_reporting to E_ALL | > > >> E_STRICT during development (in php.ini, httpd.conf or .htaccess). > > > > echo $remo->test() should output 2 on the web page. However I got a > > > zero size output html file, which means there is something wrong with > > > code. If I comment out the class part it will work without problem. I > > > just can't figure out what's wrong with the class. I am using IIS6. I > > > couldn't find display_error in php.ini. > > > Just add: > > display_errors = 1 > > see also:http://nl2.php.net/manual/en/ref.errorfunc.php > > > And, looking at it more closely, you seem to have forgotten the <?php ?> > > tags in your classfile. Adding those makes it work here. > > -- > > Rik Wasmus > > Thanks. Find out it is stupid Windows related problem. Appreciate your > . Hey Rik, Do you have idea why I got Fatal error: Call to undefined function test() in sss.php error message when I try to call $remo->test();? Thanks. Lewis |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
..oO(myzmlm@gmail.com)
>Do you have idea why I got Fatal error: Call to undefined function >test() in sss.php error message when I try to call $remo->test();? In your code you're calling print $remo.test(); instead of print $remo->test(); which is something completely different. The second calls the correct method, while the first one tries to concatenate $remo with the result from the function test(), which obviously doesn't exist. That's why PHP complains about an unknown function and not about an unknown method. Micha |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Jan 22, 2:44 pm, Michael Fesser <neti...@gmx.de> wrote:
> .oO(myz...@gmail.com) > > >Do you have idea why I got Fatal error: Call to undefined function > >test() in sss.php error message when I try to call $remo->test();? > > In your code you're calling > > print $remo.test(); > > instead of > > print $remo->test(); > > which is something completely different. The second calls the correct > method, while the first one tries to concatenate $remo with the result > from the function test(), which obviously doesn't exist. That's why PHP > complains about an unknown function and not about an unknown method. > > Micha Thanks Micha. Just new to PHP and forgot about the concatenation always. Appreciate it. |
|
![]() |
| Outils de la discussion | |
|
|