Posted by Bonge Boo! on 05/26/05 11:24
On 26/5/05 7:53 am, in article Gnele.1486038$8l.366880@pd7tw1no, "Paul"
<freelance@dezignage.net> wrote:
> sorry just a quick note I caught myself on...
>
> inside the object you'd have to declare the variable... like so..
>
> class Cart {
> var $var;
>
> function Cart() {
> $this->var =& $GLOBALS['var'];
> }
>
> }
Ok. Been playing with all this to try to get it too work. Normally with a
function I could do the following:
$foo = "apples";
function myfunction () {
extract($GLOBALS);
$var = $foo;
print $var;
}
myfunction();
Outputs apples. Which is fine and tells me that extract($GLOBALS) puts all
variables I have defined available in the function. If I try to use this
extract($GLOBALS);
Inside my class definition I get the following error.
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or
`T_VAR' or `'}'' in /path/shoppingcart.inc.php on line 14
So I guess for some reason I can't use extract GLOBALS in a class.
When I try to use a defined constant when setting up my class variables then
it doesn't seem to stick. I would have thought the below should work.
var $password = SQL_PASSWORD;
But nothing seems to be assigned to $password.
If I try
var $password = $GLOBALS['password'];
or
var $password =& $GLOBALS['password'];
I get Parse error.
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?
Navigation:
[Reply to this message]
|