Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php interactive shell doesn't have any output?

Tags:

php

macos

bash-3.2$ php -a Interactive shell

php > $a = null || "hi" php > echo $a php > $b = "hi" php > echo $b 

As you can see here, nothing is being echoed.
Why is that? I'm using Mac OS X lion. =\ (fresh install)

like image 647
NullVoxPopuli Avatar asked Aug 22 '11 14:08

NullVoxPopuli


People also ask

How do I run PHP interactive shell?

The CLI SAPI provides an interactive shell using the -a option if PHP is compiled with the --with-readline option. As of PHP 7.1. 0 the interactive shell is also available on Windows, if the readline extension is enabled. Using the interactive shell you are able to type PHP code and have it executed directly.

Does PHP have a REPL?

PHP has a REPL; if you haven't used it yet, run php –a in a terminal. This will take you to the interactive PHP prompt at which you can enter your code. All programming language REPLs work essentially the same way.

What is php shell?

PHP Shell or Shell PHP is a program or script written in PHP (Php Hypertext Preprocessor) which provides Linux Terminal (Shell is a much broader concept) in Browser. PHP Shell lets you to execute most of the shell commands in browser, but not all due to its limitations.


2 Answers

You've forgoten to put semicolons at the end of each line. Should be:

php > $a = null || "hi"; php > echo $a; php > $b = "hi"; php > echo $b; 
like image 110
Napas Avatar answered Sep 27 '22 23:09

Napas


I had the same problem:

php > echo $undefined_var 

but after put ; in other line

php > ; 

Result:

 Undefined variable: "undefined" in php shell code on line 2 

So, is possible make this:

php > echo 123456 php > ; php > echo 123456; 
like image 38
Wallace Maxters Avatar answered Sep 28 '22 00:09

Wallace Maxters