Re: References challenge with PHP4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Alterisio wrote:
> 2007/3/20, Jochem Maas <jochem@xxxxxxxxxxxxx <mailto:jochem@xxxxxxxxxxxxx>>:
> 
>     Robert Cummings wrote:
>     > On Tue, 2007-03-20 at 11:52 +0100, Jochem Maas wrote:
>     >> ok, I tried it in a whole number of variations -
>     >> no joy.
>     >>
>     >> you should use php5 if you want this kind of reference
>     >> stuff - in php5 it just works, php 4 will give you big headaches.
>     >
>     > Now now, don't be calling PHP5 "ALL THAT" when it can't do it right
>     > either (or did you not check it using PHP5 ;) ;)
> 
>     god knows what I did - obviously something different to what I thought
>     I was testing :-/
> 
>     > Everything works fine
>     > in PHP4 (also for PHP5 in this case if you just understand that static
>     > vars are buggy *lol* -- and this is first time I've noticed this
>     bug).
> 
>     I have never run into this bug before ... nice catch, seems like
>     a viable item for a bug report.
> 
> 
> Actually, is not a bug, is expected behaviour and documented in the manual
> 
> http://php.net/static
> 
> See the last section, named "references with global and static variables"

I have 2 issues with this:

1. the docs specify php4/ZendEngine1 which suggests php5 is not prone to
this implementation error, the following code seems to suggest that from the user's
POV the problem no longer exists (as long as there is no use of the reference operator
inconjunction with objects) in php5 (using the erf operator in php5 with objects is
almost always wrong anyway):

class Test {
public $foo;
private static $inst;
function get() { if(!isset(self::$inst)) self::$inst = new self; return self::$inst; }
}
$foo = Test::get();
$foo2 = Test::get();

$foo->foo = "foo";
var_dump($foo, $foo2, ($foo === $foo2));

$foo2->foo = "bar";
var_dump($foo, $foo2);

2. should I have to care about the way something is implemented internally
in order to use a given piece of language functionality without running into
problems that have a serious wtf factor? I feel not.

oh well.

> 
> static and global are implemented internally as references, that makes
> storing references into static variables impossible (which can be solved
> by using arrays of references as seen in Robert Cummings example).

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux