Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial PHP 变量怎么突然就消失了?

PHP 变量怎么突然就消失了?

Jun 23, 2016 pm 01:27 PM

我遇到一个特别奇怪的问题,用POST获取一个表单传递过来的数据,并把它赋予一个变量,这个变量在刚获取时用echo打印是没有问题的,可以正常显示。但在函数执行的过程中居然消失了!!!
本来以为是变量转换的过程中没写对引起的,但看了一下又不是,特别是奇怪的一点是:
在我使用strtotime这个函数之前echo打印这个变量没有问题!直接echo strtotime($time);也没问题,但当我执行了$time=strtotime($time);之后再次echo打印发现居然是空的!!!空的!!!

PS:之前也遇到一次很神奇的事,控制器的数据已经正确传递给前端页面,但就是不显示,只要我在控制器里print_r($res);打印这个数组的时候发现页面对应的位置里,它居然能显示了!!!
这是ecshop的bug吗?还是什么?大神指点一下!


回复讨论(解决方案)

贴出你的代码看看。。。

这个的话,是不是你的POST值没传过来啊?你重新提交下表单再试试呢!

贴出你的代码看看。。。


<?php $partners = $_POST['partners'];$starttime = $_POST['starttime'];$endtime1 = $_POST['endtime'];$sort_order = $_POST['sort_order'];@$id = $_POST['id'];$act = $_GET['act'];$actarr = array('add','edit');if(!in_array($act,$actarr) || ($id == '')){	header('Location: partners.php?act=list');}if(!empty($partners) && !empty($starttime) && !empty($endtime1)){	if(!get_magic_quotes_gpc())	{		$partners = addslashes($partners);	}	$starttime = strtotime($starttime);	$endtime = strtotime($endtime1);	@ $db = new mysqli('localhost', 'root', 'root', 'zhubao');	$db->set_charset("utf8");	if(mysqli_connect_errno()){		echo 'Error: Could not connect to database. Please try again later.';		exit;	}	if($act == 'add'){		$sql = "insert into ecs_partners (partners, starttime, endtime, sort_order)".	" values('".$partners."', ".$starttime.", ".$endtime.", ".$sort_order.")";	}elseif($act =='edit'){		$sql = "update ecs_partners set partners='".$partners."', starttime=".$starttime.		", endtime=".$endtime.", sort_order=".$sort_order." where id=".$id;	}	$res = $db->query($sql);	if($res){		echo "插入成功, 3秒后跳?<br />";		echo "或<a href='partners.php?act=list'>???接直接跳?</a>";		//header("Location: partners.php?act=list");		header("Refresh:3; url=partners.php?act=list");	}else{		echo "插入??出?,?稍後重?.<br />";		echo "或<a href='partners.php?act=list'>??回到主?面</a>";	}	$db->close();}?>
Copy after login

贴出你的代码看看。。。


有的,我试过了,做过测试的,前面都有输出,就是经过了$endtime=strtotime($endtime);这个步骤后发现值居然空了,百思不得其解,不知道是什么原因

贴出你的代码看看。。。

忘了说了,时间因为用js判断处理,所以我直接传了

$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??

$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??


传过来的是一个格式化的时间字符串:2015-09-05,echo出来的是转换后的时间戳,可以正常输出。
关键是赋值语句之后再打印这个变量的时候居然是空的


$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??


传过来的是一个格式化的时间字符串:2015-09-05,echo出来的是转换后的时间戳,可以正常输出。
关键是赋值语句之后再打印这个变量的时候居然是空的
我在自己的电脑上用你的说法测试,结果是正常的,没有楼主说的问题。。。真诡异- -空的意思是null吗



$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??


传过来的是一个格式化的时间字符串:2015-09-05,echo出来的是转换后的时间戳,可以正常输出。
关键是赋值语句之后再打印这个变量的时候居然是空的
我在自己的电脑上用你的说法测试,结果是正常的,没有楼主说的问题。。。真诡异- -空的意思是null吗
恩恩,另外我又试了一下一下,发现var_dump(strtotime($endtime))变成了bool(false)



$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??


传过来的是一个格式化的时间字符串:2015-09-05,echo出来的是转换后的时间戳,可以正常输出。
关键是赋值语句之后再打印这个变量的时候居然是空的
我在自己的电脑上用你的说法测试,结果是正常的,没有楼主说的问题。。。真诡异- -空的意思是null吗
这种事情太奇怪了,文字也表达不清,我试试找找其他同学吧

搞不明白……艾特版主来看看……




$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??


传过来的是一个格式化的时间字符串:2015-09-05,echo出来的是转换后的时间戳,可以正常输出。
关键是赋值语句之后再打印这个变量的时候居然是空的
我在自己的电脑上用你的说法测试,结果是正常的,没有楼主说的问题。。。真诡异- -空的意思是null吗
恩恩,另外我又试了一下一下,发现var_dump(strtotime($endtime))变成了bool(false)
var_dump的时候不该是$endtime1吗,你dump的$endtime变量此时不存在肯定输出false,你是不是变量名弄乱了?



$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??


传过来的是一个格式化的时间字符串:2015-09-05,echo出来的是转换后的时间戳,可以正常输出。
关键是赋值语句之后再打印这个变量的时候居然是空的
我在自己的电脑上用你的说法测试,结果是正常的,没有楼主说的问题。。。真诡异- -空的意思是null吗
天,我直接用字符串var_dump(strtotime('2070-01-01'))输出居然是false




$endtime = strtotime($endtime1);
对于strtotime函数:成功则返回时间戳,否则返回 FALSE 
你的$endtime1传过来具体是什么值??echo strtotime($endtime1)是多少??


传过来的是一个格式化的时间字符串:2015-09-05,echo出来的是转换后的时间戳,可以正常输出。
关键是赋值语句之后再打印这个变量的时候居然是空的
我在自己的电脑上用你的说法测试,结果是正常的,没有楼主说的问题。。。真诡异- -空的意思是null吗
恩恩,另外我又试了一下一下,发现var_dump(strtotime($endtime))变成了bool(false)
var_dump的时候不该是$endtime1吗,你dump的$endtime变量此时不存在肯定输出false,你是不是变量名弄乱了?
不好意思,我这边又改了一下名称。这个会不会跟php版本有关?我转换打印了2010-01-01的时候输出时间戳是正常的,但40以上的都false了,php5.6.11

这是 strtotime 适用范围的问题
手册中有:

可推知 strtotime 不能处理 2069 以后的日期
这是儿孙们的事情,不该由你操心的

原来是这么回事么。。。。。。

这是 strtotime 适用范围的问题
手册中有:

可推知 strtotime 不能处理 2069 以后的日期
这是儿孙们的事情,不该由你操心的

可以的,我用同学电脑确认过了

原来是这么回事么。。。。。。

什么意思?


这是 strtotime 适用范围的问题
手册中有:

可推知 strtotime 不能处理 2069 以后的日期
这是儿孙们的事情,不该由你操心的

可以的,我用同学电脑确认过了 你是说,你同学能strtotime打印出2070年之后的时间戳??



这是 strtotime 适用范围的问题
手册中有:

可推知 strtotime 不能处理 2069 以后的日期
这是儿孙们的事情,不该由你操心的

可以的,我用同学电脑确认过了 你是说,你同学能strtotime打印出2070年之后的时间戳??
恩恩,2080也可以,另外我独自建立一个新的文件直接用strtotime打印2070不行,所以我觉得有可能是php的问题

看了回复,感觉很神奇的样子~




这是 strtotime 适用范围的问题
手册中有:

可推知 strtotime 不能处理 2069 以后的日期
这是儿孙们的事情,不该由你操心的

可以的,我用同学电脑确认过了 你是说,你同学能strtotime打印出2070年之后的时间戳??
恩恩,2080也可以,另外我独自建立一个新的文件直接用strtotime打印2070不行,所以我觉得有可能是php的问题 有可能是版本或php配置的问题。正常情况下应该是像你同学那样能正常打印,变量也不会丢失的。。





这是 strtotime 适用范围的问题
手册中有:

可推知 strtotime 不能处理 2069 以后的日期
这是儿孙们的事情,不该由你操心的

可以的,我用同学电脑确认过了 你是说,你同学能strtotime打印出2070年之后的时间戳??
恩恩,2080也可以,另外我独自建立一个新的文件直接用strtotime打印2070不行,所以我觉得有可能是php的问题 有可能是版本或php配置的问题。正常情况下应该是像你同学那样能正常打印,变量也不会丢失的。。

可能吧,我是自己搭建的环境,改的地方挺少的,估计有什么模块没有开启。
Ps:不知道你有没有用过php5.6.12,这个版本我在几台电脑上试了一下,发现phpinfo里没有curl任何信息,只显示了作者名称

Y2K38 漏洞

Y2K38,又称 Unix Millennium Bug, 此漏洞将会影响到所有 32 位系统下用 UNIX 时间戳整数来记录时间的 PHP,及其它编程语言。一个整型的变量所能保存的最大时间为 2038 年 1 月
19 日 03:14:07。超过这个时间后,整型数值将会溢出。从 1970 年 01 月 01 日开始,到世界标准时 2038 年 01 月 19 日星期二凌晨 03:14:07 超过 2^31 ? 1。2^31 ? 1 就是
0x7FFFFFFF,相信很多编程员都看过,在 32 位系统里,这表示最大的有符号整数。如果用它来表示秒数,大概相当于 68.1 年,从 1970 年到 2038 年刚好是这个数。

64 位系统会受到影响吗?

理论上不会,强烈建议进行一下测试。64 位系统下可以保存的日期最远日期是现在宇宙年龄的 21 倍~ 292 亿年。

我本地也是64位系统,但是我发现也有这个问题,不过我看了下apache是32位的,所以不是只有64位系统就ok了,apache也要是64位的才可以避免

那么32位机器上解决
PHP 从 5.2 版本开始引入了一个 DateTime 的类(5.1 中开始实验加入,5.3 版本中扩展了一些方法)。
是不是64位apache就能解决问题我也不确定,我也在查64位的apache下载,还没找明白,大家一起试试。
额,应该有64位apache吧?呵呵

Y2K38 漏洞

Y2K38,又称 Unix Millennium Bug, 此漏洞将会影响到所有 32 位系统下用 UNIX 时间戳整数来记录时间的 PHP,及其它编程语言。一个整型的变量所能保存的最大时间为 2038 年 1 月
19 日 03:14:07。超过这个时间后,整型数值将会溢出。从 1970 年 01 月 01 日开始,到世界标准时 2038 年 01 月 19 日星期二凌晨 03:14:07 超过 2^31 ? 1。2^31 ? 1 就是
0x7FFFFFFF,相信很多编程员都看过,在 32 位系统里,这表示最大的有符号整数。如果用它来表示秒数,大概相当于 68.1 年,从 1970 年到 2038 年刚好是这个数。

64 位系统会受到影响吗?

理论上不会,强烈建议进行一下测试。64 位系统下可以保存的日期最远日期是现在宇宙年龄的 21 倍~ 292 亿年。

我本地也是64位系统,但是我发现也有这个问题,不过我看了下apache是32位的,所以不是只有64位系统就ok了,apache也要是64位的才可以避免


我选的都是64位的

你试试echo strtotime('2038/01/19 11:14:08'); 和echo strtotime('2038/01/19 11:14:07');是不是07是可以输出的,08就不能了,溢出问题是肯定的,但是是不是win64位系统就能解决了,我还没测试成功!但是我觉得linux 64位应该是没有问题的。

看来理论上不会,不是实际情况的不会,我win64位,软件也是64位是不行的,你说你朋友是可以的,你可以问问他php版本,看看是不是最新的就没有问题,我的php是5.5.15

你试试echo strtotime('2038/01/19 11:14:08'); 和echo strtotime('2038/01/19 11:14:07');是不是07是可以输出的,08就不能了,溢出问题是肯定的,但是是不是win64位系统就能解决了,我还没测试成功!但是我觉得linux 64位应该是没有问题的。


试了,跟你想的一模一样,08的一片空白


你试试echo strtotime('2038/01/19 11:14:08'); 和echo strtotime('2038/01/19 11:14:07');是不是07是可以输出的,08就不能了,溢出问题是肯定的,但是是不是win64位系统就能解决了,我还没测试成功!但是我觉得linux 64位应该是没有问题的。


试了,跟你想的一模一样,08的一片空白
另外,我用的是win7 64bit



你试试echo strtotime('2038/01/19 11:14:08'); 和echo strtotime('2038/01/19 11:14:07');是不是07是可以输出的,08就不能了,溢出问题是肯定的,但是是不是win64位系统就能解决了,我还没测试成功!但是我觉得linux 64位应该是没有问题的。


试了,跟你想的一模一样,08的一片空白
另外,我用的是win7 64bit

在Windows环境里,PHP6以下的版本,是不支持64位的,这个PHP官方已经确认了这个问题,因为PHP5的Windows版本是测试版本,没有正式版本,这个可以在官方网站上搜索的到。

简单的说,在Windows环境里,PHP5的intval最大只支持到2147483647,也就是只支持32位,即使你的系统、WebServer、PHP都是64位版本,也只支持32位

看了网上有人说64位php使用的仍然是32位模式,只有linux或者win 64位下php7才是使用64位模式,我在下php7,看看能不能解决。

用64位的Linux版本的php就不会有问题了

用64位的Linux版本的php就不会有问题了


自己用源码的方式搭建centos+Nginx+php+mariadb服务器失败了很多次,已经元气大伤


用64位的Linux版本的php就不会有问题了


自己用源码的方式搭建centos+Nginx+php+mariadb服务器失败了很多次,已经元气大伤

元气大伤,也要继续尝试,
因为环境部署 和 问题排查的要求,不管公司大小,都需要rd能承担至少一半运维的工作,
而且PHP的生产环境,我还没见过使用Windows的

经测试,php7可以解决这个问题,不过php7没有正式发布。有没有其他bug问题就不知道了。



用64位的Linux版本的php就不会有问题了


自己用源码的方式搭建centos+Nginx+php+mariadb服务器失败了很多次,已经元气大伤

元气大伤,也要继续尝试,
因为环境部署 和 问题排查的要求,不管公司大小,都需要rd能承担至少一半运维的工作,
而且PHP的生产环境,我还没见过使用Windows的

经测试,php7可以解决这个问题,不过php7没有正式发布。有没有其他bug问题就不知道了。



非常感谢,晚点我再把同学的php版本发过来

谢谢各位,谢谢

不好意思,是我错了,我同学用的是CentOS5.4,64位的

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1250
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

See all articles