note 57469 modified in function.call-user-func by danbrown

From: Date: Sat, 19 Jul 2008 21:07:24 +0000
Subject: note 57469 modified in function.call-user-func by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141739@lists.php.net to get a copy of this message
>phil at gettcomm dot com >22-May-2002 04:51 >if you need to get a reference back from a method, you can work around >call_user_func()'s shortcomings like this: > Naaa! Having back a reference is a real problem, but it can be solved by mean of eval(), instead of using call_user_func: <?php class Node { var $name; var $child; function Node ( $name ) { $this->name = $name; } function &getChild () { return $this->child; } } $p = new Node ( 'Father' ); $c = new Node ( 'Child' ); $p->child = &$c; eval ( "\\$cref = &\\$p->getChild ();" ); $cref->name = 'Another Child'; // Prints out 'Another Child' echo "****** After eval c = " . $c->name . "\\n\\n"; ?> --was-- >phil at gettcomm dot com >22-May-2002 04:51 >if you need to get a reference back from a method, you can work around >call_user_func()'s shortcomings like this: > Naaa! Having back a refererence is a real problem, but it can be solved by mean of eval(), instead of using call_user_func: <code> class Node { var $name; var $child; function Node ( $name ) { $this->name = $name; } function &getChild () { return $this->child; } } $p = new Node ( 'Father' ); $c = new Node ( 'Child' ); $p->child = &$c; eval ( "\\$cref = &\\$p->getChild ();" ); $cref->name = 'Another Child'; // Prints out 'Another Child' echo "****** After eval c = " . $c->name . "\\n\\n"; </code> http://php.net/manual/en/function.call-user-func.php

« previous php.notes (#141739) next »