Re: [PHP4BETA] PHP(4) Object Oriented Suggestions (+Bug)
| From: | Zeev Suraski | Date: | Fri, 11 Feb 2000 17:47:42 +0000 |
| Subject: | Re: [PHP4BETA] PHP(4) Object Oriented Suggestions (+Bug) | ||
| References: | 1 | Groups: | php.dev php.version4 |
| Request: | Send a blank email to php-dev+get-15384@lists.php.net to get a copy of this message | ||
On Fri, 11 Feb 2000, Vincent Vollers wrote:
> 1) When creating a new var, if that var is an object, let it reference to
> it automaticly instead of creating a copy
>
> $a = new $fooBar();
> $b = $a;
> // Make this work ^_^ much more logical (according to OOP)
Been there, done that, won't happen (read the archives).
> 2) At the moment PHP breaks any referencing when created inside functions,
> you cannot return a reference, nor can you set a global var to reference to
> anything, the only possible way is to create an array, and make an element
> of that array be the reference.
>
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>>>>>>>>> Doesn't Work
> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>
>
> function Foo(&$Bar1,&$Bar2) {
> $Bar2 = &$Bar1;
> echo $Bar2; // Prints "Bar"
> echo "<BR>";
> return $Bar2;
> }
>
> $Foo1 = "Bar";
> $Foo2 = false;
>
> Foo($Foo1, $Foo2);
> $Foo1 = "FooBar?";
> echo $Foo2; // Prints "" .. Should Print "FooBar?"
>
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>>>>>>>>> Doesn't Work
> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>
>
> function Foo(&$Bar1) {
> $Bar2 = &$Bar1;
> echo $Bar2; // Prints "Bar"
> echo "<BR>";
> return $Bar2;
> }
>
> $Foo1 = "Bar";
> $Foo2 = false;
>
> $Foo2 = Foo($Foo1);
> $Foo1 = "FooBar?";
> echo $Foo2; // Prints "Bar" .. Should Print "FooBar?"
>
>
> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>>>>>>> ** ! Works ! **
> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>
>
> function Foo(&$Bar2) {
> $Bar1 = Array();
> $Bar1[1] = &$Bar2;
> echo $Bar1[1]; // Prints "Bar"
> echo "<BR>";
> return $Bar1;
> }
>
> $Foo1 = "Bar";
> $Foo2 = false;
>
> $Foo2 = Foo($Foo1);
> $Foo1 = "FooBar?";
>
> echo $Foo2[1]; // Prints "FooBar?"
>
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>>>>>>>>> Doesn't Work
> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>
>
> $FooBar = false;
>
> function Foo(&$Bar2) {
> global $FooBar;
>
> $FooBar = &$Bar2;
> echo $FooBar; // Prints "Object"
> echo "<BR>";
> }
>
> $Foo1 = "Bar";
> $Foo2 = false;
>
> Foo($Foo1);
> $Foo2 = &$FooBar;
> $Foo1 = "FooBar?";
>
> echo $Foo2; // Prints "" .. Should print "FooBar?"
>
>
> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>>>>>>> ** ! Works ! **
> >>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>
>
> $FooBar = Array();
>
> function Foo(&$Bar2) {
> global $FooBar;
>
> $FooBar[1] = &$Bar2;
> echo $FooBar[1]; // Prints "Bar"
> echo "<BR>";
> }
>
> $Foo1 = "Bar";
> $Foo2 = false;
>
> Foo($Foo1);
> $Foo2 = &$FooBar[1];
> $Foo1 = "FooBar?";
> echo $Foo2; // Prints "FooBar?"
>
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> As you can see, it only works when the var is passed through an array.
The latest CVS of PHP 4.0 has been added the ability to have functions
return references, using a special notation (that happened a few weeks
ago). This feature will be a part of PHP 4.0.
Zeev
--
Zeev Suraski <zeev@zend.com>
http://www.zend.com/