I want to Learn php & mySQL and I purchased a book (php&mySql: the missing manuals 2edition)
I installed Wampserver2.4 on win8 64bit machine.
Server Configuration
Apache Version : 2.4.4
PHP Version : 5.4.12
in first lesson i got this error :(
Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:\wamp\www\study\sayHello.php on line 5
this is the php code on file "sayHello.php"
<?php
echo "Hello there. So I hear you're learning to be a PHP programmer!\n";
echo "Why don't you type in your name for me:\n";
$name = trim(fgets(STDIN));
echo "\nThanks, " . $name . ", it's really nice to meet you.\n\n";
?>
Just define STDIN
constant at top of your file,
define('STDIN',fopen("php://stdin","r"));
Try adding this on the top of your file
define('STDIN',fopen("php://stdin","r"));
It looks like you are trying to use a constant called STDIN
, which does not exist.
STDIN is used to get a currently open stream with fopen.
$file = fopen('file/path');
$name = trim(fgets(STDIN));
Using STDIN
without a currently open stream would not work.
I also believe that STDIN
only works under cli, but am not 100% sure. If that is the case, use the same code as above, but replace STDIN
with $file
;
If you want your code to be executed properly with the "STDIN" Constant you have two options:
# php -r "fgets(STDIN);"
or :
# gedit file.php //make a file with <?php fgets(STDIN); ?>
# php file.php // execute the file
The other option :
#php
<?php
fgets(STDIN);
?>
//click on ctrl+d
Will not work !! you may have to define the "STDIN" constant inside your code as mentioned above.