Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP shebang inappropriate?

Tags:

php

shebang

I was going to add a shebang line to a php script

#!/bin/env php

but I was looking around and people don't seem to be doing this.

  • http://github.com/zurb/foundation/blob/master/marketing/about.php
  • http://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Cart.php
  • http://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php

Is it "inappropriate" or against some rule to shebang a php file?

like image 206
Zombo Avatar asked Mar 15 '26 16:03

Zombo


2 Answers

Usually hashbangs are only added when the PHP script is intended to be run from the command line, where it is useful. It is not typically useful to run PHP scripts designed for the web on the command line, and as such, people do not add hashbangs to them.

Also, I believe that in non-CLI PHP environments, PHP will echo the hashbang.

like image 89
icktoofay Avatar answered Mar 17 '26 05:03

icktoofay


If it's a UNIX shell script the shebang is appropriate. If it's for a webpage it isn't.

like image 43
SpliFF Avatar answered Mar 17 '26 06:03

SpliFF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!