Home  >  Article  >  Backend Development  >  PHP语言,未赋值的变量?

PHP语言,未赋值的变量?

WBOY
WBOYOriginal
2016-06-23 14:26:211290browse

http://docs.php.net/manual/zh/language.types.null.php

问题:
1.

<?php    if ($x)               echo "1";    else       echo "0";?>


ubuntu@ubuntu:~$ php /var/www/b.php
PHP Notice:  Undefined variable: x in /var/www/b.php on line 3

上面代码,第3行错了!

PHP语法,变量可以不赋值。
如果,变量不赋值,其值是:NULL。对么?
为什么编译,第3行出错呢?




回复讨论(解决方案)

刚在WINDOWS下试了下,没出错,输出0

用isset 判断 试试

变量$x,没赋值。
那么,其值是:NULL。

布尔型NULL,是false。
对么?

刚在WINDOWS下试了下,没出错,输出0

ubuntu12.04 LTS,终端调试有错误!

这与你的 php 错误检查级别设置有关

只在屏蔽掉 E_NOTICE 级别检查时,才不会报 Notice 警告
程序中 error_reporting(E_ALL ^ E_NOTICE);
php.ini 中 error_reporting=E_ALL ^ E_NOTICE
这少要有一个

这与你的 php 错误检查级别设置有关

只在屏蔽掉 E_NOTICE 级别检查时,才不会报 Notice 警告
程序中 error_reporting(E_ALL ^ E_NOTICE);
php.ini 中 error_reporting=E_ALL ^ E_NOTICE
这少要有一个

PHP官方手册(中文),哪有这些说明?
给个链接!

这与你的 php 错误检查级别设置有关

只在屏蔽掉 E_NOTICE 级别检查时,才不会报 Notice 警告
程序中 error_reporting(E_ALL ^ E_NOTICE);
php.ini 中 error_reporting=E_ALL ^ E_NOTICE
这少要有一个

变量$x,没赋值。
那么,其值是:NULL。

布尔型NULL,是false。
对么? null是没赋值,false是值,表示否定。

错误报告级别

随着版本的升级,对于代码的要求也不断提升。
现在版本,对这类要报notice的。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn