PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Need with class
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Need with class

Réponse
 
LinkBack Outils de la discussion
Vieux 22/01/2008, 18h41   #1
myzmlm@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Need with class

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;
}
}
  Réponse avec citation
Vieux 22/01/2008, 18h54   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need with class

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
  Réponse avec citation
Vieux 22/01/2008, 19h02   #3
myzmlm@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need with class

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.
  Réponse avec citation
Vieux 22/01/2008, 19h08   #4
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need with class

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
  Réponse avec citation
Vieux 22/01/2008, 19h16   #5
myzmlm@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need with class

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
.
  Réponse avec citation
Vieux 22/01/2008, 19h34   #6
myzmlm@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need with class

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
  Réponse avec citation
Vieux 22/01/2008, 19h44   #7
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need with class

..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
  Réponse avec citation
Vieux 22/01/2008, 19h47   #8
myzmlm@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need with class

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h52.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24599 seconds with 16 queries