Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Patchwork: "Only variables should be passed by reference" #2

Spudley opened this issue Apr 2, 2012 · 2 comments

Error in Patchwork: "Only variables should be passed by reference" #2

Spudley opened this issue Apr 2, 2012 · 2 comments


Copy link

@Spudley Spudley commented Apr 2, 2012

I have been trying to get going with Patchwork, in order to help me write unit tests to a legacy PHP codebase. Unfortunately, I have run into an error which I can't resolve.

Whenever I try to call an overridden method, I get the following error: "Only variables should be passed by reference"

I have a very simple test case that demonstrates this:


class patchworkTest extends PHPUnit_Framework_TestCase {
    public function testOverrideMe() {
        Patchwork\replace("clsOverrideMe::sayBar", function() { return "overridden"; });
        $result = clsOverrideMe::sayBar();  //standard $result='bar', but with Patchwork, $result='overridden'.

...and clsOverrideMe.php:

class clsOverrideMe {
    public static function sayBar() {
        return "bar";

Then at the command prompt, I get the following:

C:\DEVELOPMENT\_tests>phpunit patchworkTest.php
PHPUnit 3.5.14 by Sebastian Bergmann.


Time: 0 seconds, Memory: 6.75Mb

There was 1 error:

1) patchworkTest::testClsOverrideMe
Only variables should be passed by reference


Tests: 1, Assertions: 0, Errors: 1.

Any idea what I'm doing wrong here? Or have I found a bug in Patchwork?

The above is the simplest possible example I could come up with in the context of PHPUnit (ie how I want to use it). It also throws the same error when written as a simple PHP program.

PHP version 5.3.8 on Windows7.

Copy link

@antecedent antecedent commented Apr 5, 2012

This seems to overlap with this other report of yours, which I've already addressed. Thanks!

@antecedent antecedent closed this Apr 5, 2012
Copy link
Contributor Author

@Spudley Spudley commented Apr 10, 2012

It does indeed overlap -- it's the same issue: I posted this ticket first, and then decided to try fixing it myself; the second ticket was generated by Github when I posted the fix. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.