Re: "Only variable references should be returned by reference"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robert Cummings wrote:
> On Tue, 2005-07-19 at 22:10, Jason Wong wrote:
> 
>>On Wednesday 20 July 2005 07:32, Marc G. Fournier wrote:
>>
>>
>>>Which is?  If its:
>>
>>Yep.
>>
>>
>>>; at function call time.  This method is deprecated and is likely to be
>>>; unsupported in future versions of PHP/Zend.  The encouraged method of
>>>; specifying which arguments should be passed by reference is in the
>>>function ; declaration.  You're encouraged to try and turn this option
>>>Off and make ; sure your scripts work properly with it in order to
>>>ensure they will work ; with future versions of the language (you will
>>>receive a warning each time ; you use this feature, and the argument
>>>will be passed by value instead of by ; reference).
>>>allow_call_time_pass_reference = On
>>
>>The pass by reference thing works regardless of the above setting. 
>>Enabling the setting disables the warnings and vice-versa.
>>
>>
>>>It already is ...
>>
>>Are you sure that:
>>
>>1) you're looking at the correct php.ini
>>2) the setting is not being changed elsewhere
>>
>>If the warning annoys you just tone down the error reporting level.
>>
>>
>>>Is there another one I should be looking at? :(
>>
>>Not that I'm aware of.
> 
> 
> This isn't related to allow_call_time_pass_reference. It's a new notice
> that came with PHP 4.4.0 to inform developers of possible incorrect
> code. For instance the following will generate it:
> 
>     function &$foo()
>     {
>         return null;
>     }
> 
> According to internals before 4.4.0 such methods caused the occasional
> (almost impossible to track down) memory corruption bugs. You're only
> relief is to tone down the error reporting level (Which will knock out
> other notices during development but will be great for a production
> server), or do as I did and install a custom error handler that filters
> this notice specifically (I have to work with some ezproject code for a
> client which is disgusting and is filled with all kinds of notices not
> to mention on one page almost a thousand of this particular breed).

It still needs some tuning, but eventually it will also catch problems like:

  function foo(&$arg) {
    $arg = "foo";
  }
  function bar() {
     return "abc";
  }
  foo(bar());

PHP4.4 will still happily let you run this code.  PHP-5.1 throws a fatal
error now.

It is obviously incorrect code and needs to be fixed.

In the case of returning a reference to something bogus, it's not quite
obvious that it is incorrect, hence the notice, but it is still
something that needs to be looked at.  For legacy code, ignore notices
for now and poke the authors to fix their code.

-Rasmus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux