PurplePixel Posted March 4, 2021 Posted March 4, 2021 Debugging eval() issues (hooks, etc.) are very hard since the code is loaded in the memory, so I wrote a class that can write in the /tmp/ directory the php eval'd code so one can use xdebug on the code. Moreover, it does search for the namespace and the first class name and sets the file names based on that (for the ones that do not have a class insides the file name will be sha1($code)). I have shared this patch in hope you can implement something similar for a better debugging mechanism. It can be imported with git so you can verify it. It would be great if the core would use a class like EvalDebug::eval($code) instead of eval($code) which is impossible to modify to write to disk (and believe me I really tried to do that). Even if the EvalDebug class does not contain anything else except eval($code) inside. Like this: class _EvalDebug { public static function eval(string $code) { return eval($code) } } This way, developers can manipulate the mechanism of eval(). Let me know what you think, thanks! eval_disk_writer.patch
Stuart Silvester Posted March 4, 2021 Posted March 4, 2021 You might want to enable the 'DEBUG_TEMPLATES' constant in that case, it'll avoid the use of eval for debugging. CoffeeCake 1
PurplePixel Posted March 5, 2021 Author Posted March 5, 2021 @Stuart Silvester It probably avoids only for the themes. But not for plugin and application hooks as they are generated on-the-fly. An it's not the only code that is generated on the fly. Search for eval( in the source code so you can see how many times you will find this.
CodingJungle Posted March 10, 2021 Posted March 10, 2021 in my toolbox app, in settings, there is an option for "patch init.php", what this does, will rewrite the monkeypatch method of the init class, to write hooks to a folder and use those instead of eval'ing them, so if there is an error with them, its a proper backtrace instead of a pseudo one thru eval. note: you shouldn't use this on a live site and it can't be used in the community in the cloud, so a localhost or a dev site should suffice. it does modify a core file from IPS, so if you have any unexpected behaviors, you should restore the init.php from the IPS download. you can grab the latest toolbox from this repo: https://github.com/codingjungle/toolbox make sure you are on the dev branch when you checkout. PurplePixel 1
PurplePixel Posted March 10, 2021 Author Posted March 10, 2021 Thank you @CodingJungle, looks really good. I will test it. It's been frustrating not having a proper way of debugging code and if the codebase would have used some class in order to eval the code instead direct eval() that would be easy to hook up to and do this.
Recommended Posts