PHP(4) Object Oriented Suggestions (+Bug)
| From: | Vincent Vollers | Date: | Fri, 11 Feb 2000 17:29:54 +0000 |
| Subject: | PHP(4) Object Oriented Suggestions (+Bug) | ||
| Groups: | php.dev php.version4 | ||
| Request: | Send a blank email to php-dev+get-15382@lists.php.net to get a copy of this message | ||
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)
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.
- Vincent Vollers