1

I have a very simple test.php file:

<?php

echo 'Hello World';

Then I run it from Mac Shell: php test.php But it does not echo anything. Looks like it's blocked for some reason, like this:

Running php script from shell shows nothing

If I use invalid syntax in the file, for example:

<?php

invalid syntax

Then I can see the error output:

PHP Parse error:  syntax error, unexpected 'syntax' (T_STRING) in .../test.php on line 3

Parse error: syntax error, unexpected 'syntax' (T_STRING) in .../test.php on line 3

What's wrong with it?

FYI:

  • Running php -i can print php.ini info
  • Running echo 'test' can print 'test'
10
  • what do you see if you run $ echo 'test' Commented Jan 14, 2016 at 5:08
  • Which command you have tried actually. I mean what you meant by Samples Commented Jan 14, 2016 at 5:13
  • @SanjayKumarNS Samples is just the containing folder name. I run the command in that folder. Commented Jan 14, 2016 at 5:29
  • @PradeepSanjaya $ echo 'test' will print 'test' Commented Jan 14, 2016 at 5:30
  • 1
    Maybe php is aliased (try which php or run \php test.php). Commented Jan 14, 2016 at 5:38

1 Answer 1

1

Turning my comments into an answer as requested:

Here are two possible reasons why php command doesn't work as expected:

  1. Maybe it is aliased (try which php or prepend a backslash (\) to the command)

  2. You mentioned that you had a directory named php on your working directory. Well, zsh has a feature called AUTO_CD that may have interfered in this case. Basically AUTO_CD allows you to switch directories without typing cd and can be disabled by adding unsetopt autocd to file.

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

1 Comment

I think i got the cause. When I'm seeing the issue, I'm letting my PHPStorm to listen to xdebug connections (doesn't hit any break point). If I stop PHPStorm, it works again.

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.