Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 496935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:43:59+00:00 2026-05-13T05:43:59+00:00

Seemingly something of a misnomer, as pass by reference is deprecated in PHP 5.3…

  • 0

Seemingly something of a misnomer, as pass by reference is deprecated in PHP 5.3… anyway, what I’m trying to do is write a unit test framework using reflection, that allows you to pass arguments to a method which requires a reference. e.g.

class Bar {
    function TestMethod($arg1, &$result) {
        $result = 'hello';
        return true;
    }
}

$rc = new ReflectionMethod('Bar', 'TestMethod');
$return_val = $rc->invokeArgs($instance, $arguments);

Now, I found a forum post at http://www.phwinfo.com/forum/comp-lang-php/273316-how-invoke-reflectionmethod-pass-variable-reference-asargument.html which clued me into simply sticking a variable reference into my $arguments array:

$arguments = array('arg1', &$byref_result);

This does work but gives a ‘Deprecated: Call-time pass-by-reference has been deprecated’ error. I’d like to make sure this code is forwards compatible, so if they remove it completely in PHP 6 I won’t be screwed. Obviously I’d prefer not to have to rewrite any code in my project because of shortfalls in my testing framework. Any ideas or suggestions? Thanks! 🙂

P.S. I tried to hit up phpunit’s documentation to see if it can do it but the site seems to be down for the moment. Any links to “don’t re-invent the wheel” solutions very welcome, though I’m also curious about the question itself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:43:59+00:00Added an answer on May 13, 2026 at 5:43 am

    no problems with this code

    class Bar {
        function test($arg1, &$result) {
            $result = 'hello';
        }
    }
    
    $arguments = array('', &$b);
    $rc = new ReflectionMethod('Bar', 'test');
    $rc->invokeArgs(new Bar, $arguments);
    var_dump($b);
    

    prints “hello”, no warnings

    can you post your exact code?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement something seemingly very simple, and I have been beating
I'm trying to do something seemingly simple: ensure that Application_BeginRequest is called for every
So I'm trying to achieve something seemingly very basic in jQuery. I have a
I'm using the Last.fm API and I stuck on something seemingly fairly simple. One
Every time I try to do something seemingly-simple in CSS, it doesn't work. I
I want to do something seemingly very simple, but I can't find anything about
banging my head against the wall for something seemingly dead simple. Here it is:
Seemingly simple, but I cannot find anything relevant on the web. What is the
Seemingly a simple enough question, but I cannot work it out. I want to
I was writing a (seemingly) straight-forward SQL snippet that drops a column after it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.