-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Interface constructor if present will break Magento compilation #8607
Comments
@redboxmarcins make sense, function funcA($arg1, $arg2) { } } $refl = new ReflectionClass('SomeClass'); var_dump($refl->isInstantiable()); // bool(true) |
Strongly disagree. Please take a look on some http://stackoverflow.com/a/689488 and http://stackoverflow.com/a/41685659.
First of all, Magento in general and its compiler in particular should honor and encourage best practices. So, when PHP design flaws we should mitigate problems instead of providing support. It is a good thing to disallow shooting yourself in the foot whenever it is possible. Obviously, compiler must not display nonsense like |
@orlangur |
@maghamed, I have nothing against defensive programming,
Hope you are not going to add check for
? Notice in this case looks perfectly valid to me as it allows to fail fast. Anyway, this issue was already fixed and delivered to |
@orlangur one more time, current implementation with the fix you mentioned would not allow you to instantiate such class without E_NOTICE: class SomeClass { Proposed fix - In any case contract of getConstructor() could return NULL, so next chain access That's one of the Defensive Programming principle. |
Okok, if this code is still reachable for I was saying that I'm against such check in a place where we actually instantiate such object, like https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php#L91 |
…pilation - $class->isInterface() method of an php reflection class will implement the getConstructor() function not to pull any dependencies from the interface constructor. So we must have to add this condition in order to call getConstructor(). This solves the issue
Pull Request #9524 has been merged to 2.1-develop branch. Thank you @LoganayakiK for your contribution! |
Internal ticket to track issue progress: MAGETWO-69019 |
[ACQE-5692, ACQE-5700] MFTF update to ^4.6 & Test Stabilization
Preconditions
Steps to reproduce
php bin/magento setup:di:compile
Expected result
Actual result
PHP Notice: Trying to get property of non-object in /var/www/html/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php on line 30
Problem is here
magento2/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php
Line 28 in b1e56ed
If class hasn't got '__construct' method it will be skipped, but if method exist
$class->getConstructor()
will return NULLand
$class->getConstructor()->class
obviously will generate fatal errorSimplest fix
The text was updated successfully, but these errors were encountered: