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

Syntax error trying to mock Memcache on PHP 7.1 #259

Open
neerolyte opened this issue Feb 12, 2018 · 3 comments
Open

Syntax error trying to mock Memcache on PHP 7.1 #259

neerolyte opened this issue Feb 12, 2018 · 3 comments

Comments

@neerolyte
Copy link

Just running:

<?php
require_once('vendor/autoload.php');
Phake::mock('Memcache');

With Memcache installed results in:

[root@4bc9bbc433aa tests]# php debug.php
PHP Parse error:  syntax error, unexpected '$', expecting variable (T_VARIABLE) in /var/www/tests/vendor/phake/phake/src/Phake/ClassGenerator/EvalLoader.php(59) : eval()'d code on line 477

Here's the class definition that's trying to eval:
classDef.php.txt

The problem seems to be that it's failing to extract the parameter names for the get method and so the signature is not valid php:

	public function get($, &$, &$)

This works fine under PHP 5.4 & 5.6, it's only failing for me under PHP 7.1 - using Phake v2.3.2 across all 3.

@neerolyte neerolyte changed the title Syntax error trying to Mock Memcache on PHP 7.1 Syntax error trying to mock Memcache on PHP 7.1 Feb 12, 2018
@neerolyte
Copy link
Author

Adding:

    protected function getParameterName(ReflectionParameter $param) {
        $name = $param->getName();
        if (!empty($name)) return $name;
        return "param".$param->getPosition();
    }

to MockClass.php and then calling it from the two places that use the parameter name seems to resolve my issues.

Just figuring out how to put together tests etc so I can submit a sensible PR.

@neerolyte
Copy link
Author

Checking out v2.3.2 and running phpunit gets to a memcache test and then crashes:

...
Starting test 'PhakeTest::testStubbingMemcacheSetMethod'.
PHP Parse error:  syntax error, unexpected '$', expecting variable (T_VARIABLE) in /var/www/Phake/src/Phake/ClassGenerator/EvalLoader.php(58) : eval()'d code on line 477

... so there's a reasonable chance this is something fairly unique in my environment.

@neerolyte
Copy link
Author

@mlively Could I get any feedback on whether there's something I can improve in the PR to progress this faster?

luketw pushed a commit to luketw/Phake that referenced this issue Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant