ID:               44139
 Updated by:       [EMAIL PROTECTED]
 Reported By:      andrea at 3site dot it
-Status:           Open
+Status:           Feedback
 Bug Type:         Scripting Engine problem
 Operating System: Windows XP
 PHP Version:      5.2.6
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi




Previous Comments:
------------------------------------------------------------------------

[2008-02-18 11:33:43] andrea at 3site dot it

As expected, this problem is present on ReflectionMethod too.

Basically, the summary of this bug is wrong and I guess that correct
could be the changed one.

I tested both problems in PHP 5.2.5 and 5.2.6-dev.

This example shows the problem using methods as well.

<?php

class Test{
    public  function unshift(&$arr, $mix){
        return  array_unshift($arr, $mix);
    }
}

$instance   = new Test;
$arr        = array(2, 3, 4);
$ref        = new ReflectionMethod('Test', 'unshift');

// WARNING
$ref->invoke($instance, &$arr, 1);
$ref->invokeArgs($instance, array(&$arr, 0));
var_dump($arr); // [0,1,2,3,4]

// FATAL ERROR
$ref->invoke($instance, $arr, 1);
$ref->invokeArgs($instance, array($arr, 0));
var_dump($arr);
exit;

?>

Thanks for solving this problem.
Kind Regards.

------------------------------------------------------------------------

[2008-02-18 09:46:58] andrea at 3site dot it

Sorry, this is what I would like to be able to do:

<?php
$arr    = array(2, 3, 4);
$ref    = new ReflectionFunction('array_unshift');
$ref->invoke($arr, 1);
$ref->invokeArgs(array($arr, 1));
var_dump($arr);
exit;
?>

Without fatal errors, simply because if send by reference is
deprecated, ReflectionFunction (... and I didn't test ReflectionMethod
...) should be able to manage correctly variables by references.

This is another Fatal Error example:

<?php
function unshift(&$arr, $mix){
    return  array_unshift($arr, $mix);
}
$arr    = array(2, 3, 4);
$ref    = new ReflectionFunction('unshift');
$ref->invoke($arr, 1);
$ref->invokeArgs(array($arr, 1));
var_dump($arr);
exit;
?>

I hope these examples explain correctly where and what is the problem.
Kind Regards

------------------------------------------------------------------------

[2008-02-18 09:42:17] andrea at 3site dot it

Felipe, I'm testing PHP Version 5.2.6-dev and I have the same problem.

<?php
$arr    = array(2, 3, 4);
$ref    = new ReflectionFunction('array_unshift');
$ref->invoke(&$arr, 1);
$ref->invokeArgs(array(&$arr, 1));
var_dump($arr);
exit;
?>

Warning: Call-time pass-by-reference has been deprecated; If you would
like to pass it by reference, modify the declaration of [runtime
function name](). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true in
your INI file in ...

I guess above warning should not exists. So, can you confirm that this
is a bug?
Cheers

------------------------------------------------------------------------

[2008-02-17 23:41:00] [EMAIL PROTECTED]

$ref->invoke(&$arr, 1);
$ref->invokeArgs(array(&$arr, 0));
var_dump($arr); // correct and expected result

Doesn't show warning on 5.2.6 and 5.3. That was my message.

------------------------------------------------------------------------

[2008-02-17 23:17:39] andrea at 3site dot it

Hi Felipe, I don't understand your messages.

I know that it generates a Fatal error as I know that send the array
forcing reference works as expected but it generates a warning.

As I wrote on php.net manual too, to solve this strange behaviour I
used a "non-sense" strategy (at least for me) ...

$arr = array(2, 3, 4);
$ref = new ReflectionFunction('array_unshift');
$ref->invokeArgs(array_merge(array(&$arr), array(1)));
$ref->invokeArgs(array_merge(array(&$arr), array(0)));
// $arr == [0,1,2,3,4]

I can't understand why one single value is accepted by reference inside
an array while more than one is not accepted.

Since PHP 5 should manage by itself references I think that
ReflectionFunction should do the same, without reference requirement but
working as expected.

Do you think am I wrong?
Kind Regards

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/44139

-- 
Edit this bug report at http://bugs.php.net/?id=44139&edit=1

Reply via email to