You are here: Re: Creating a class and reusing variables... « PHP SQL « IT news, forums, messages
Re: Creating a class and reusing variables...

Posted by Bonge Boo! on 05/27/05 19:55

On 26/5/05 8:13 pm, in article jdple.1486825$Xk.1472227@pd7tw3no, "Paul"
<freelance@dezignage.net> wrote:

>> So it seems like the $GLOBAL keyword is what is causing the problem when
>> called inside a class. Does that make sense? It can't be that I am using
>> reserved keywords can it?
>>
>
> I think the reason you're getting a parser error is nothing to do with
> globals... you're giving it a value in the wrong place... it should be
> like this...
>
> class someClass {
> var $password;
>
> function someClass() { (or __Construct() in PHP 5)
> $this->password = $GLOBALS['password'];
> }
> function someOtherFunctionInsideTheClass() {
> $password =& $this->password;
> // or you could probably even do this..
> extract($GLOBALS);
> }
> }
>
> but if you need it in every function of your class, I would just add a
> reference in the beginnign of each function.. and that's it.. (that
> shouldn't take that long...
>
> function anotherFunctionOfTheClass ($arg, $arg2) {
> $password =& $this->password;
> }
>
> maybe this will help? :)

I understand why it doesn't work. It just doesn't look very elegant have
repetitions of the same variable declarations inside each function.

I've just bunged my variable declarations in an include, then inside the
function just have:

function myfunc() {

$bignumber = $GLOBALS['number']*2.5;
return $bignumber;
}

It works. Dunno why I didn't do that to start with. Probably I'm a bit dim.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация