Need help with class

Need help with class

am 22.01.2008 19:41:01 von myzmlm

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 help me? Thanks.

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();

?>




test

print $remo.test();
print "sssssss";
}
catch (Exception $e)
{
// Catch the exception and handle it as usual
throw new Exception($e->getMessage());
}
?>





pd.php
class pd{
private $dsn;

function _pd() {
$dsn = 'mysql://pd:password@127.0.0.1/pd';
}
function test(){
return 2;
}
}

Re: Need help with class

am 22.01.2008 19:54:05 von luiheidsgoeroe

On Tue, 22 Jan 2008 19:41:01 +0100, 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 help me? Thanks.
>
> > function __autoload($class)
> {
> if (file_exists($file =3D "$class.php"))
> {
> include($file);
> }
> else
> {
> throw new Exception("Class $class not found");
> }
> }
>
> try
> {
> class_exists('pd');

What do you expect this does?

> $remo =3D new pd();
>
> ?>
>
>
>
>
>

test

> > 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

Re: Need help with class

am 22.01.2008 20:02:31 von myzmlm

On Jan 22, 1:54 pm, "Rik Wasmus" wrote:
> On Tue, 22 Jan 2008 19:41:01 +0100, 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 help me? Thanks.
>
> > > > 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();
>
> > ?>
> >
> >
> >
> >
> >

test

> > > > 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.

Re: Need help with class

am 22.01.2008 20:08:21 von luiheidsgoeroe

On Tue, 22 Jan 2008 20:02:31 +0100, wrote:

> On Jan 22, 1:54 pm, "Rik Wasmus" wrote:
>> On Tue, 22 Jan 2008 19:41:01 +0100, 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 p=
age
>> > either. Any one could help me? Thanks.
>>
>> > >> > function __autoload($class)
>> > {
>> > if (file_exists($file =3D "$class.php"))
>> > {
>> > include($file);
>> > }
>> > else
>> > {
>> > throw new Exception("Class $class not found");
>> > }
>> > }
>>
>> > try
>> > {
>> > class_exists('pd');
>>
>> What do you expect this does?
>>
>> > $remo =3D new pd();
>>
>> > ?>
>> >
>> >
>> >
>> >
>> >

test

>> > >> > 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 =3D 1
see also: http://nl2.php.net/manual/en/ref.errorfunc.php

And, looking at it more closely, you seem to have forgotten the =
=

tags in your classfile. Adding those makes it work here.
-- =

Rik Wasmus

Re: Need help with class

am 22.01.2008 20:16:10 von myzmlm

On Jan 22, 2:08 pm, "Rik Wasmus" wrote:
> On Tue, 22 Jan 2008 20:02:31 +0100, wrote:
> > On Jan 22, 1:54 pm, "Rik Wasmus" wrote:
> >> On Tue, 22 Jan 2008 19:41:01 +0100, 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 help me? Thanks.
>
> >> > > >> > 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();
>
> >> > ?>
> >> >
> >> >
> >> >
> >> >
> >> >

test

> >> > > >> > 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
> tags in your classfile. Adding those makes it work here.
> --
> Rik Wasmus

Thanks. Find out it is stupid Windows related problem. Appreciate your
help.

Re: Need help with class

am 22.01.2008 20:34:44 von myzmlm

On Jan 22, 2:16 pm, myz...@gmail.com wrote:
> On Jan 22, 2:08 pm, "Rik Wasmus" wrote:
>
>
>
> > On Tue, 22 Jan 2008 20:02:31 +0100, wrote:
> > > On Jan 22, 1:54 pm, "Rik Wasmus" wrote:
> > >> On Tue, 22 Jan 2008 19:41:01 +0100, 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 help me? Thanks.
>
> > >> > > > >> > 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();
>
> > >> > ?>
> > >> >
> > >> >
> > >> >
> > >> >
> > >> >

test

> > >> > > > >> > 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
> > tags in your classfile. Adding those makes it work here.
> > --
> > Rik Wasmus
>
> Thanks. Find out it is stupid Windows related problem. Appreciate your
> help.

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

Re: Need help with class

am 22.01.2008 20:44:49 von Michael Fesser

..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

Re: Need help with class

am 22.01.2008 20:47:46 von myzmlm

On Jan 22, 2:44 pm, Michael Fesser 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.