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"));
when you are trying to run migration form a PHP file using
Artisan::call('migrate');
seems that's time also produce these type of error. For solve this problem you can simple replace your code with
Artisan::call('migrate', ['--force' => true ])
Make sure you use --force flag if you are in production.
Only the CLI (command line) SAPI defines I/O constants such as STDIN
, STDOUT
, and STDERR
, purely for convenience in that environment.
As stated in other answers, you can simply define these constants in your PHP code. You can also check defined()
to avoid errors when invoked via CLI. For example:
<?php
if (!defined('STDIN')) {
define('STDIN', fopen('php://stdin', 'r'));
}
However, keep in mind that php://stdin
may not work the way you expect in a non-CLI SAPI, such as Apache or FPM. For example, to access the raw POST body when executed via FPM, you would use php://input
instead.
PHP has many different SAPI (Server Application Programming Interface), that allow you to execute PHP code in various environments such as your Web server, email server, or the command line (CLI). Examples include:
Each SAPI may have slightly different initial conditions and behavior. Some other differences between the CLI SAPI and other SAPIs include:
header()
has no effect.html_errors
and output_buffering
have different default values (more appropriate for the CLI).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With