|
Posted by Jerry Stuckle on 05/07/07 14:16
gosha bine wrote:
> Vince Morgan wrote:
>> "gosha bine" <stereofrog@gmail.com> wrote in message
>> news:463ee9be$0$2889$6e1ede2f@read.cnntp.org...
>>> Vince Morgan wrote:
>>>> I guess I don't understand how references work in php;
>>>> Calling a class member function below as an example;
>>>> function &getRow()
>>>> {
>>>> return odbc_fetch_array($this->_det);
>>>> }
>>>> I would expect that I should end up with nothing as there is nothing to
>>>> actualy reference.
>>> Are you debugging with E_ALL? This actually should throw a notice ("only
>>> variables can be returned by ref" or similar).
>>
>> Yes Gosha. No warning or notice however.
>>
>> Vince
>>
>>
>
> Report a bug then. For reference, the followin throws a notice in php 5.2:
>
> function &foo($rc) {
> return mysql_fetch_array($rc);
> }
> $rc = mysql_query("SELECT 1");
> $a = foo($rc);
> // NOTICE: Only variable references should be returned by reference
>
>
Gosha,
But you're dealing with a different function, so the results may vary.
Take the following script in 5.2:
<?php
function &getArrayRef() {
static $ar = array();
return $ar;
}
function getArrayCopy() {
static $ar = array();
return $ar;
}
function &getGetArrayRef() {
return getArrayRef();
}
function &getGetArrayCopy() {
return getArrayCopy();
}
echo "Return by ref:\n";
$var1 = getGetArrayRef();
echo "Return by copy:\n";
$var2 = getGetArrayCopy();
?>
Output:
Return by ref:
Return by copy:
Notice: Only variable references should be returned by reference in
test.php on line 18
Notice that when getArrayRef returns a reference, getGetArrayRef can
return that reference with no notice. However, since getArrayCopy
returns a copy, getGetArrayCopy gets a NOTICE when it tries to return
the reference.
It looks like odbc_fetch_array is acting like the former, and
mysql_fetch_array is acting like the latter. The former way is
obviously more efficient (and flexible). But changing an array member
may have undesired effects. It's hard to know when you don't know what
the code that created the array is doing.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|