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
Fatal error: Using $this when not in object context in \lib\Preprocessor.php(40) : eval()'d code on line 1 #1
Comments
I'm afraid I won't be able to identify the problem without more context. For example, if it's a static class you're trying to override, then why does it have a __toString() method? Also, at what point exactly does the error occur? Is it thrown during redefinition, or only when the redefined method is called? It would be ideal to see the source of the static class in question, but if that's impossible, answering the above questions should also shed some light on this issue. Thank you. |
Hey antecedent, I'm not trying to override a tostring method. Actually I try to override a method of joomla's JFactory class. Here is a small part of the class: class JFactory
} Normally you call the method with JFactory::getMailer(). So I tried to override it with: Patchwork\replace("JFactory::getMailer", function() I'll have to trace when the error occurs, but I think that it is at redefinition time. |
This should now work with the 1.1.1 tag. Thanks for the report! |
That is working! Thank you very much! I have another question - do you recommend using the library on production web sites? Is it going to slow them a lot or the difference in speed is not noticeable? |
You're welcome. And as for the question, Patchwork was designed with development/testing environments in mind. Consequently, issues like performance and possible security concerns weren't taken that seriously. This doesn't necessarily mean that it will make your site unbearably slow and vulnerable, but there are absolutely no guarantees about that. The performance hit may vary wildly from site to site, so it's recommended that you measure it yourself. As for security, no actual concerns come to my mind, but given the terribly hackish preprocessing mechanism in Patchwork, you may never know. So, while you can definitely use Patchwork wherever you want, I wouldn't really recommend using it in production. |
issue with checking for incorrect int value
As of PHP 8.1, passing `null` to not explicitly nullable scalar parameters for PHP native functions is deprecated. In this case, `$class` within `applyWildcard()` may be null, which leads to the following deprecation notice as can be seen when running the tests on PHP 8.1: ``` Deprecated: class_exists(): Passing null to parameter antecedent#1 ($class) of type string is deprecated in path/to/patchwork/src/CallRerouting.php on line 141 ``` By handling `null` separately in the condition, the previous behaviour is maintained. Refs: * https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg * https://www.php.net/manual/en/function.class-exists.php
As of PHP 8.1, passing `null` to not explicitly nullable scalar parameters for PHP native functions is deprecated. In this case, `$class` within `interpretCallable()` may be null, which leads to the following deprecation notice as can be seen when running the tests on PHP 8.1: ``` Deprecated: ltrim(): Passing null to parameter antecedent#1 ($string) of type string is deprecated in path/to/patchwork/src/Utils.php on line 123 ``` By handling `null` separately and setting `$class` to an empty string, the previous behaviour is maintained. Refs: * https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg * https://www.php.net/manual/en/function.ltrim.php
Ok, I cannot get this to work. I'm trying to override a static class as described in the documenation:
Patchwork\replace("A::__toString", function()
{
return "redefined";
});
But I only get:
Fatal error: Using $this when not in object context in \lib\Preprocessor.php(40) : eval()'d code on line 1
I'm on php 5.3.1
The text was updated successfully, but these errors were encountered: