Re: [PHP-DEV] $obj = new foo() patch From: André Langhorst (A.Langhorst <email protected>)
Date: 11/10/00

> It actually always worked, but only appeared to be working. It could
> (and almost always did) end up corrupting data structures. In 4.0.4,
> this is actively detected, and prevented.

The counterproof is atteched.

Well, trust me, thereīs code out there using this procedure and itīs
working. Iīve changed that example code to reflect a more realistic
situation... and it just doesnīt work NOW and it worked before (tested
for example with a 2000-10-01 build) for ages perfectly. Perhaps we can
figure out in which case it *should* not work and add a "warning"
protection there, but this "fatal error"... umh.

To summarize:
You canīt use returned copies (and references) of variables if directly
originating from methods anymore?

Well thatīs very bad. Try out the code and notice that changing $bar,
also changes these $updated_bar(2) variables and I canīt imagine that
this is by accidently corrupted data structures, I could be wrong, sure :)

<?php
class foo {

         function &ret1(&$obj1) {
                 $obj1->a='test';
                 return $obj1; }

         function &why_not(&$obj1) {
                        $obj1->b='test';
                        return $obj1; }
         }

$bar->xyz=TRUE;
$x = new foo();
$updated_bar
=&
$x->why_not($foo=&$x->ret1($bar));
$updated_bar2
=&
$x->why_not($x->ret1($bar));
$bar->xyz=FALSE;

var_dump($updated_bar);
var_dump($updated_bar2);
?>

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>