note 27721 deleted from ref.array by sniper
| From: | sniper@php.net | Date: | Sat, 18 Oct 2003 18:03:20 +0000 |
| Subject: | note 27721 deleted from ref.array by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58835@lists.php.net to get a copy of this message | ||
Note Submitter: wheaty@planetquake.com
----
In keeping with OO principles in PHP4, if you want to pass a reference of an array to an object
(instead of using ugly global variables):
==================================
class A
{
var $myarray;
// constructor
function A ( &$array_param )
{
$this->myarray =& $array_param;
}
function put_hi()
{
$this->myarray[] = "Hi!";
}
}
$greetings = array("Hello.", "How are you doing?", "What's up?");
$myobj =& new A($greetings);
$myobj->put_hi();
print_r($greetings);
==================================
Will Output:
Array ([0] => Hello. [1] => How are you doing? [2] => What's up? [3] => Hi!)