PHP 函数不返回数据。显示错误
include("include/session.php");
class createcountdown
{
public $start;
public $howlong;
public function get(){
$this->start = $session->start; // $session->start Returns data from Mysql: 0000-00-00 00:00:00
$this->howlong = $session->howlong; // $session->howlong Returns data from Mysql: 300
$diff = $this->start-3600 + $this->howlong-time();
if($this->start + $this->howlong > time()){
list($h,$min,$sec)=explode(":",date("H:i:s",$diff));
$sum = $this->start + $this->howlong-time();
return $sum;
}
}
$obj = new createcountdown();
$result = $obj->get();
echo $result;
include("include/session.php");
class createcountdown
{
public $start;
public $howlong;
public function get(){
$this->start = $session->start; // $session->start Returns data from Mysql: 0000-00-00 00:00:00
$this->howlong = $session->howlong; // $session->howlong Returns data from Mysql: 300
$diff = $this->start-3600 + $this->howlong-time();
if($this->start + $this->howlong > time()){
list($h,$min,$sec)=explode(":",date("H:i:s",$diff));
$sum = $this->start + $this->howlong-time();
return $sum;
}
}
$obj = new createcountdown();
$result = $obj->get();
echo $result;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在使用未定义变量
$session
的属性:如果它是全局对象,请在访问它之前使用
global $session;
。You're using properties of undefined variable
$session
:If it is global object use
global $session;
before accessing it.看起来问题是
get()
中的if
后面缺少大括号。当我在
list($h,$min,$sec)=explode(":",date("H:i:s",$diff));
之后添加大括号时,代码运行没有错误。It looks like the problem is the missing brace after the
if
inget()
.When I add a brace after
list($h,$min,$sec)=explode(":",date("H:i:s",$diff));
, the code runs without an error.请关闭类
}
操作符missiongPlease close class
}
operator missiong你可以试试这个:
you can try this :