-
-
Notifications
You must be signed in to change notification settings - Fork 449
Stop hiding errors inside broken PHP files when loaded through the autoloader #1817
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
Conversation
Without the |
@luigifab I have not encountered this issue so far. It does look like you have this issue because of case sensitivity on your file system. If this is the case, we should fix the directory and/or filename as it is clearly wrong. This would also mean that Phpseclib is not working on your end as the file cannot be loaded and you just didn't know about it. I cannot think of any good reason why we would want to hide errors during PHP file loading. Whatever the reason for the |
On our installation, we have already created a symlink from phpseclib to Phpseclib to avoid an error (I don't remember why). But, for my warning, I getting it when I go to System / Configuration, when a field frontend_type is obscure. |
I added a new testcase for triggering the autoloader for a non existing class this test currently fails with this change. (which is the actual reason, why we added the @ there initially) But the issue you want to solve is definitely valid, too. We just need to find a solution which works for both cases. |
I don’t follow. You need the “@“ for a test case? |
@woutersamaey no, the testcase imitates a common usecase. in other words: remove the @, and you break at least every M1 project I ever worked on |
@Flyingmana I still don't follow. You have projects that load missing classes? |
Are you saying that openmage core tries to load classes which doesn't exist? or that extensions/custom modules are doing so? |
@tmotyl my thoughts exactly... |
We have tried the removal of the |
the testcase is pretty clear
using a class_exist() on a class which could not exist is a very normal thing in php. I just want to make sure, this still works after the change. |
In any phtml: <?php class_exists('Mage_Non_Existent') ?> Result in:
|
This is a good thing, right? |
I think if I try |
Out of curiosity, but a class that could not exist in an On another note, a warning on What if we did the following instead of ignoring all issues with an
EDIT: updated suggestion to actually work. |
Although there is an warning from the openmage autoloader when trying to load Phpseclib (suppressed by the @) there is a second autoloader registered that takes care of the loading of Phpseclib. Reordering the autoloader registrations or modifying the openmage autoloader to handle Phpseclib better should be considered to avoid any warnings. Lines 50 to 55 in f09b664
magento-lts/lib/phpseclib/bootstrap.php Lines 17 to 22 in f09b664
|
By loading |
What are we doing with this one guys? |
I vote for that, but I forgot if it works very well or not, and not deployed in production: diff --git a/app/Mage.php b/app/Mage.php
index 910cb4804..615c2aabb 100644
--- a/app/Mage.php
+++ b/app/Mage.php
@@ -47,11 +47,11 @@ $paths[] = BP . DS . 'lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage/Core/functions.php";
+include_once "phpseclib/bootstrap.php";
include_once "Varien/Autoload.php";
Varien_Autoload::register();
-include_once "phpseclib/bootstrap.php";
include_once "mcryptcompat/mcrypt.php";
/* Support additional includes, such as composer's vendor/autoload.php files */
diff --git a/lib/Varien/Autoload.php b/lib/Varien/Autoload.php
index bfaa67054..479948527 100644
--- a/lib/Varien/Autoload.php
+++ b/lib/Varien/Autoload.php
@@ -62,6 +62,6 @@ class Varien_Autoload
*/
public function autoload($class)
{
- return @include str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class))) . '.php';
+ return include str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace(['_', '\\'], [' ', DIRECTORY_SEPARATOR], $class))) . '.php';
}
}
diff --git a/lib/phpseclib/bootstrap.php b/lib/phpseclib/bootstrap.php
index 55a919e89..f3c2d2e06 100644
--- a/lib/phpseclib/bootstrap.php
+++ b/lib/phpseclib/bootstrap.php
@@ -1,9 +1,9 @@
<?php
/**
* Bootstrapping File for phpseclib
- *
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
+
if (extension_loaded('mbstring')) {
// 2 - MB_OVERLOAD_STRING
if (ini_get('mbstring.func_overload') & 2) {
@@ -13,10 +13,3 @@ if (extension_loaded('mbstring')) {
);
}
}
-
-spl_autoload_register(function($className) {
- $parts = explode('\\', $className);
- if (array_shift($parts) == 'phpseclib') {
- return include str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
- }
-});
Here, I missed Asfolny proposal. |
Im in favor of making the code not hide errors. In general i would be also in favor of moving the autoloading out of the Mage class. The current mixture of executable code and class declaration is a pain eg when using tools like phpstan. But this change is of course a separate topic/pr |
this will still cause problems, if the class does not exist, because include throws I think a notice, which then is transformed into an exception |
Description (*)
A PHP class of mine had by mistake a method return type of
: true
instead of:bool
making the PHP file unparsable.The Magento autoloader suppresses all errors, so I could not see this error at all.
Because of this, I lost many hours trying to find the error.
I believe Magento should not suppress any errors when loading files. We definately want to know about these.
Manual testing scenarios (*)
: true
instead of: bool
.Contribution checklist (*)