Pedro Posted August 22, 2018 Share Posted August 22, 2018 I've built a module which I want to validate againt validator. Among all the errors and recomendations the validator said that __DIR__ is forbidden. The line was like this: require __DIR__.'/../../lib/ProtectedResource.php'; How can I use that library without using __DIR__? Why is it forbidden? Please excuse my ignorance but I'm a PHP newbie and I did not found this information on the Internet Link to comment Share on other sites More sharing options...
Guest Posted August 22, 2018 Share Posted August 22, 2018 It is a nonsense reason. PrestaShop accepts PHP 5.4+, yet the Addons morons decline 5.3 constants. They just love to waste your time on validation... In case you wanted to know, you can use `dirname(__FILE__)` as an alternative. Link to comment Share on other sites More sharing options...
Pedro Posted August 27, 2018 Author Share Posted August 27, 2018 Thanks @PrestaRalph I did not understand the reason Link to comment Share on other sites More sharing options...
Rodrigo B Laurindo Posted August 9, 2019 Share Posted August 9, 2019 I know this is an old topic, but there is a reason for this behavior. PrestaShop 1.6.1.x is supposed to be fully compatible with PHP from versions 5.2 to 7.1. PHP 5.2 didn't support the __DIR__ constant. So, your module wouldn't be fully compatible with all installations of 1.6.1.x. But, of course, I think you should be able to simply specify that your module requires PHP 5.3... Link to comment Share on other sites More sharing options...
Jezza Posted September 29, 2020 Share Posted September 29, 2020 Good question. I arrived here from the PrestaShop module validator (https://validator.prestashop.com/auth/login) after receiving an error for using the __DIR__ constant. Funny how its used is all over their official modules. I have it from the composer autoloader. Anyway I will use the dirname(__FILE__) constant instead - it's common practice in WordPress too. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now