note 90095 added to function.func-get-args
| From: | mitko at edabg dot com | Date: | Mon, 06 Apr 2009 10:48:45 +0000 |
| Subject: | note 90095 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152855@lists.php.net to get a copy of this message | ||
<?php
/*
This example demonstrate how to use unknown variable arguments by reference.
func_get_args() don't return arguments by reference, but
debug_backtrace() "args" is by reference.
In PHP 5 this have no particular sense, because calling with arguments by reference
is depreciated and produce warning.
*/
class foo {
var $bar = "default bar";
function foo(/*variable arguments*/) {
// func_get_args returns copy of arguments
// $args = func_get_args();
// debug_backtrace returns arguments by reference
$stack = debug_backtrace();
$args = array();
if (isset($stack[0]["args"]))
for($i=0; $i < count($stack[0]["args"]); $i++)
$args[$i] = & $stack[0]["args"][$i];
call_user_func_array(array(&$this, 'bar'), $args);
}
function bar($bar = NULL) {
if (isset($bar))
$this->bar = & $bar;
}
}
$global_bar = "bar global";
$foo = & new foo();
echo "foo->bar: ".$foo->bar."</br>\n";
$foo->bar = "new bar";
echo "global_bar: ".$global_bar."</br>\n";
/*
Result:
foo->bar: default bar</br>
global_bar: bar global</br>
*/
$foo = & new foo(&$global_bar);
echo "foo->bar: ".$foo->bar."</br>\n";
$foo->bar = "new bar";
echo "global_bar: ".$global_bar."</br>\n";
/*
Result:
foo->bar: bar global</br>
global_bar: new bar</br>
*/
?>
----
Server IP: 217.75.128.29
Probable Submitter: 84.1.242.66
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- https://master.php.net/note/edit/90095
Del: integrated -- https://master.php.net/note/delete/90095/integrated
Del: useless -- https://master.php.net/note/delete/90095/useless
Del: bad code -- https://master.php.net/note/delete/90095/bad+code
Del: spam -- https://master.php.net/note/delete/90095/spam
Del: non-english -- https://master.php.net/note/delete/90095/non-english
Del: in docs -- https://master.php.net/note/delete/90095/in+docs
Del: other reasons-- https://master.php.net/note/delete/90095
Reject -- https://master.php.net/note/reject/90095
Search -- https://master.php.net/manage/user-notes.php