1

Is there a way to set (or add to) the PHP include_path from an environment variable when running CLI PHP? I'm looking for the PHP analog to Java's CLASSPATH or Perl 5's PERL5LIB. My gut tells me it should be there, but I can't find it.

If there really is no such thing, then I guess the follow-up is: is there a best practice for achieving this? Keep in mind that, in my case, the include_path should not be the same for all users, or even for every application.

5
  • One word (?): php.ini. If I'm correct, it is loaded when using PHP-CLI. Commented Apr 22, 2015 at 17:35
  • But, "in my case, the include_path should not be the same for all users, or even for every application". But, php.ini is, unless I'm missing something Commented Apr 22, 2015 at 17:36
  • No, you can have a different file per folder. And you can pass an argument to load a different php.ini file. Commented Apr 22, 2015 at 17:41
  • 1
    If you know what path a class is in, then you can explicitly load it from the fully-qualified path, rather than from a relative expression that needs resolving with include paths. Commented Apr 22, 2015 at 17:43
  • If you look at the documentation (php.net/manual/en/features.commandline.options.php) You can see you can use the -c <file> arguments or the -d foo[=bar] in which foo is the name of the key and you set the value (e.g.: php -d include_path='/my/folder/with/files' /file/to/run.php). Commented Apr 22, 2015 at 17:50

1 Answer 1

0

This other answer points out that you can use the -d argument to set include_path in the CLI.

php -d include_path=/path/to/config.php script.php

-d is used to set INI directives at runtime, so you don't have any changing code/configs/directories

Note: @Ismael answered this in a comment, I just moved the info to an answer, where it stackoverflowily should be.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.