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

runkit_method_* doesn't work for internal classes like PDO #60

Open
ptrofimov opened this issue Jan 9, 2014 · 7 comments
Open

runkit_method_* doesn't work for internal classes like PDO #60

ptrofimov opened this issue Jan 9, 2014 · 7 comments

Comments

@ptrofimov
Copy link

Even if flag runkit.internal_override=1. Is it possible to enable it?

@tony2001
Copy link
Contributor

tony2001 commented Jan 9, 2014

Do you have a short reproduce code?

@ptrofimov
Copy link
Author

Sure, the code

if (!runkit_method_rename('PDO', 'query', '__query')) {
    throw new RuntimeException('Failed to rename PDO::query to PDO::__query');
}

produces an exception and a warning

PHP Warning:  runkit_method_rename(): class PDO is not a user-defined class

@ptrofimov
Copy link
Author

For example, this is being checked here https://github.com/zenovich/runkit/blob/master/runkit_methods.c#L132. Is it possible to remove this condition and allow to modify any classes?

@baptistepillot
Copy link

ptrofimov : did you try to remove the condition ? Did it work ?

I just tried to remove the three conditions on internal method and internal function into this file : and it worked. But it's dangerous ! For now :

  • if you runkit_method_rename('PDO', 'query', '__query'), don't forget to get it back before the end of your script with a runkit_method_rename('PDO', '__query', 'query'), or your next executions of the same script will give you beautiful crashes or seg fault.
  • if your script stops because of errors before your "reverse rename", you'll get the same problem. Or consider using of php as CGI instead of apache MODULE (as CGI php will be clause when the scripts ends, and a real new php will start on the next call of your script. Slower but this is a working patch for this kind of problem).

The commit that does that :
baptistepillot@409e270
Beware : this is a dangerous classified patch !

@everflux
Copy link

Would be great if this could be toggle without patching the source.
If there is a way to wrap core classes instead that would help as well. Example: That a

new PDO(...)

returns a custom class instead which can then include logging or other logic.

@edhgoose
Copy link

I'm not sure if it helps anyone, but I'm running into a similar problem that I think this would resolve. We're trying to test Time based functionality, and while runkit can override functions like time() without problem, it cannot do the same for \DateTime(). I'm instead using this little hack:

    // First, override time() using runkit
    $now = new \DateTime();
    $now->setTimestamp(time());

This ensures the \DateTime is set to the mocked time value.

If there was an easy way to override \DateTime that'd be marvellous (or an alternative way to address this would be great)?

@cmb69
Copy link

cmb69 commented Aug 3, 2016

For the record: that had already been reported as https://bugs.php.net/bug.php?id=57330.

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

No branches or pull requests

7 participants