Use of undefined constant STDIN - assumed 'STDIN' in C:\wamp\www\study\sayHello.php on line 5

拥有回忆 提交于 2019-12-17 16:29:19

问题


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";

?>

回答1:


Just define STDIN constant at top of your file,

define('STDIN',fopen("php://stdin","r"));



回答2:


Try adding this on the top of your file

define('STDIN',fopen("php://stdin","r"));



回答3:


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;




回答4:


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.



来源:https://stackoverflow.com/questions/21184962/use-of-undefined-constant-stdin-assumed-stdin-in-c-wamp-www-study-sayhello

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!