【未定义变量】Notice: Undefined variable解决方法

WBOY
Release: 2016-06-13 12:58:49
Original
859 people have browsed it

【未定义变量】Notice: Undefined variable
错误提示:Notice: Undefined variable: yan_zheng_shu in
代码:

$yan_zheng_shu .= dechex(mt_rand(1, 15));
Copy after login
Copy after login

“.=”就报错,但是结果能正常显示,“+=”也一样,就“=”没事。

怎么办呀?上 php.ini 把错误提示关了?

还是在“.=”前面先给它赋个空字符?

还是前面加“@”?

哪种方法标准规范一些呢?

感谢各位您了。


------解决方案--------------------
本帖最后由 xuzuning 于 2012-11-24 09:40:09 编辑

给 $yan_zheng_shu 赋个初值
$yan_zheng_shu = '';
$yan_zheng_shu .= dechex(mt_rand(1, 15));
------解决方案--------------------
PHP虽然不需要声明变量,
但仍然会产生一个E_NOTICE级别的错误。

$yan_zheng_shu .= dechex(mt_rand(1, 15));
Copy after login
Copy after login

相当于
$yan_zheng_shu = $yan_zheng_shu . dechex(mt_rand(1, 15));
Copy after login

很明显未定义

养成好习惯是必要的。
------解决方案--------------------
你知道.=的意义么,赋值是从右到左的,就这段肯定是没有定义前面那个变量的

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!