Jump to content

What can I use instead of __DIR__?


Recommended Posts

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

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

  • 11 months later...

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

  • 1 year later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...