4

How can I start the php interactive mode (php -a) with pre-executing certain commands?

The option -B (--process-begin) seems exactly what I want, but it looks like this can not be combined with `-a-:

$ php -B '$x = true; echo $x;' -a
Either execute direct code, process stdin or use a file.

The php binary should be invoked from within another php console scripted and then handed over to the user.

Is it possible to supply code before handing over?

Or is there another PHP option which could be used?

1
  • 3
    did you consider auto_preprend_file option in your php.cli.ini ? Commented Mar 27, 2013 at 12:46

1 Answer 1

5

Based on @Justin T.'s comment.

The auto_prepend_file option can be used to include some script:

# cat foo.php 
$x = true;

# php -d auto_prepend_file=foo.php -a
Interactive shell

php > echo $x;
1
Sign up to request clarification or add additional context in comments.

1 Comment

if you're inside your php project managed by composer you can use php -d auto_prepend_file=vendor/autoload.php -a in order to launch php in interactive mode aware of all your libraries and bundles in vendor directory...

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.