Closed adri closed 9 years ago
@adri looks like interesting I will try it in a separate branch, thx!
Cool :-) good luck.
Hi,
I looked at this library, which looks like awesome, but in documentation we can see:
I can suppose that most of programmers will argue that it’s impossible to intercept system function without extensions such as runkit. Yes, it’s absolutely true that we can not change the function that already loaded into the memory of PHP. However there is a small loophole in the PHP that can be exploited for free.
See here.
Here, aop php extension allow to override php functions/classes. Go-AOP does not allow it.
Just read a little further :-)
Go! AOP framework has an experimental support for system function interception from the version 0.4.0. This means that there is an ability to create an advice for system functions!
oh oops. :)
@adri I guess you refer to things explained in this very interesting article. Here's one excerpt:
Go! AOP framework has an experimental support for system function interception from the version 0.4.0. This means that there is an ability to create an advice for system functions!
Function interception can be very-very slow, so please do not try to intercept all system functions in all namespaces. However it’s so amazing
So ok we see it's for test purpose only or very very precise interception. With that indeed we should be able to intercept all calls to the following system php functions:
date_create
date
gettimeofday
gmdate
microtime
strtotime
time
But... it remains the \DateTime
object... I guess we have to check that we can intercept its own constructor call prior to go for a POC.
Go-aop can't overwrite that class?
In php-vcr we overwrite the \SoapClient
in a similar way, like here https://github.com/php-vcr/php-vcr/blob/master/tests/VCR/CodeTransform/SoapCodeTransformTest.php.
Should be possible in a way with go-aop too.
I also advise to only use this for test or development purposes.
@adri ok thx to point out for \SoapClient
so yes looks like checklist is good enough for a POC GO ;)
Thank you for this library! I like to ask if you know go-aop-php and if yes, why is AOP PHP used instead?
I'm using a similar technique in php-vcr and it works quite well for mocking arbitrary functions.