I'm running linux with a bash 4 compatible shell.
I have two files:
A.class.php:
<?php
class A{
public static function foo(){
echo "foo\n";
}
}
A.php:
<?php
A:foo();
Is it possible to require A.class.php before running A.php from the command line without editing the files?
Something like:
php --require "A.class.php" A.php
I tried to concatenate <?php require 'A.class.php' ?>
with the contents of the file A.php and then pipe it to php like:
echo "<?php require 'A.class.php'?>$(<A.php)" | php
which works quite well but is kind of hackish and a lot to write. Maybe there is some easier way to do this?
You could use a -d directive=value
to set the auto_prepend_file directive.
php -d auto_prepend_file=A.class.php -f A.php
Or instead of passing script file names you could pass php code that loads the scripts directly as a parameter:
php -r "require 'A.class.php'; require 'A.php';"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With