用php5.2写的程序在切换到5.3之后出现notice错误???
以前一直用的是php5.2,但是最近发现版本略低,就切换成了php5.3(我用的是phpstudy组合包),但是在切换后,以前用php5.2写的程序就会出现notice提示,虽然不影响运行出正确结果。
图片描述
我以后应该用那种版本的php??我还是喜欢用组合包之类的
这是报错页面的代码:
<code><?php if(!empty($_POST)){ $tt= $_POST['tt']; $id= $_POST['id']; $pwd= $_POST['pwd']; $wb= $_POST['wb']; $car= $_POST['car']; $yx= $_POST['yx']; } echo "<br/>"; // echo "<br>编程语言:$t33"; // print_r($t); echo "编程语言:"; // 方法1:遍历数组,到那时最后的逗号无法避免 // foreach ($t as $key => $value) { // echo $value . ","; // } // 方法2:使用for循环 $len=count($tt);//获得数组的长度 $str=""; for ($i=0; $i账号:$id"; echo "<br>密码:$pwd"; echo "<br>介绍:$wb"; echo "<br>汽车:$car"; echo "<br>院系:$yx"; ?> <form action="" method="POST" name="bb"> <table border="1"> <h2 id="form表单练习">form表单练习</h2> <p id="lan">你喜欢那种<font>语言</font>?</p> <input type="checkbox" name="tt[]" value="python"> python <input type="checkbox" name="tt[]" value="javascript"> javascript <input type="checkbox" name="tt[]" value="php" checked>php <input type="checkbox" name="tt[]" value="swift"> swift <hr> <p>login in</p> Account:<input type="text" name="id" value=""> Password:<input type="password" name="pwd" value=""><br> <input type="submit" name="sub" value="login"> <input type="reset" name="re" value="cancel"> </table> </form> ![图片描述][1] 我感觉不是代码的问题,还是因为php版本切换导致的,你说呢??? </code>
回复内容:
以前一直用的是php5.2,但是最近发现版本略低,就切换成了php5.3(我用的是phpstudy组合包),但是在切换后,以前用php5.2写的程序就会出现notice提示,虽然不影响运行出正确结果。
图片描述
我以后应该用那种版本的php??我还是喜欢用组合包之类的
这是报错页面的代码:
<code><?php if(!empty($_POST)){ $tt= $_POST['tt']; $id= $_POST['id']; $pwd= $_POST['pwd']; $wb= $_POST['wb']; $car= $_POST['car']; $yx= $_POST['yx']; } echo "<br/>"; // echo "<br>编程语言:$t33"; // print_r($t); echo "编程语言:"; // 方法1:遍历数组,到那时最后的逗号无法避免 // foreach ($t as $key => $value) { // echo $value . ","; // } // 方法2:使用for循环 $len=count($tt);//获得数组的长度 $str=""; for ($i=0; $i账号:$id"; echo "<br>密码:$pwd"; echo "<br>介绍:$wb"; echo "<br>汽车:$car"; echo "<br>院系:$yx"; ?> <form action="" method="POST" name="bb"> <table border="1"> <h2 id="form表单练习">form表单练习</h2> <p id="lan">你喜欢那种<font>语言</font>?</p> <input type="checkbox" name="tt[]" value="python"> python <input type="checkbox" name="tt[]" value="javascript"> javascript <input type="checkbox" name="tt[]" value="php" checked>php <input type="checkbox" name="tt[]" value="swift"> swift <hr> <p>login in</p> Account:<input type="text" name="id" value=""> Password:<input type="password" name="pwd" value=""><br> <input type="submit" name="sub" value="login"> <input type="reset" name="re" value="cancel"> </table> </form> ![图片描述][1] 我感觉不是代码的问题,还是因为php版本切换导致的,你说呢??? </code>
这跟php版本没太大关系,而是你应该养成一个良好的编程习惯,不确定是否有值时要判断有才输出.
否则未关闭错误提示直接路径全部爆出来了
你应该改成:
<code>if(isset($user['yx'])){ echo $user['yx']; } //或者 if(!empty($user['yx'])){ echo $user['yx']; }</code>
另外建议直接使用最新的稳定版本,截止到[2016/04/30]的LTS版本:5.6.21
跟版本没关系,变量没定义就使用,当然要报错!请一定注意,在使用非预定义变量的时候一定要先定义才能使用!
另外关于版本问题,根据市场份额和具体项目决定
目前建议在生产环境使用5.6
当然5.3用的最多 5.4其次
7速度最快
$tt没定义就用。而且这种没定义和版本无关,本来就会报错,只是php.ini的错误设置级别不同造成你以为5.2的就不报错
用isset先判断

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
