Re: Re: MySQL Problem
| From: | OrangeHairedBoy | Date: | Thu, 03 Oct 2002 12:51:08 +0000 |
| Subject: | Re: Re: MySQL Problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-118728@lists.php.net to get a copy of this message | ||
Well, that's just a typo...of course there should be a () to make it call a
function...
The whole point to my postings is that I can't get the darn variable to stay
in place!!! Look where it says "Prints NOTHING".
Does anyone know why it doesn't print "Hello World"???
::Lewis
"Mike Ford" <M.Ford@lmu.ac.uk> wrote in message
news:7E070107F405BA4790C43526CC4985A10132AC23@lis-exchange3.lmu.ac.uk...
> > -----Original Message-----
> > From: OrangeHairedBoy [mailto:me@orangehairedboy.com]
> > Sent: 03 October 2002 09:39
> >
> > Here's a simplier version...and I'm still having a problem
> > with it. It's
> > driving me insane!!! :)
> >
> > class MySQL
> > {
> > function SET ( )
> > {
> > $this->MYVAR = "Hello World!";
> > }
> > function RETREIVE ( )
> > {
> > print $this->MYVAR;
> > }
> > }
> > $helpme = new MySQL;
> > $helpme->SET;
> > $helpme->RETREIVE; /* Prints NOTHING */
>
> I'm pretty sure you have to add () on the end of those function names to
get
> PHP to actually *call* the function, so you need:
>
> $helpme->SET();
> $helpme->RETREIVE();
>
> Without the parentheses, PHP evaluates the name of the function (returning
> its "handle"), but then doesn't know what to do with it so just throws it
> away on seeing the terminating semicolon. As far as PHP is concerned, you
> could quite legitimately want to do something entirely different with the
> handle, such as assigning it to a variable -- PHP won't assume you want to
> call it as a function just because it happens to be a function name. For
> instance, the following should work (I think! - although I haven't tested
> it):
>
> $method = $helpme->SET;
> $method();
>
> In fact, you can ask PHP to try and call anything as a function by
appending
> parentheses, so this should work too:
>
> $method = "SET";
> $helpme->$method();
>
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@lmu.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211