PHP 函数不返回数据。显示错误

发布于 2024-10-06 04:46:54 字数 764 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一江春梦 2024-10-13 04:46:54

您正在使用未定义变量 $session 的属性:

$this->start = $session->start;
$this->howlong = $session->howlong;

如果它是全局对象,请在访问它之前使用 global $session;

You're using properties of undefined variable $session:

$this->start = $session->start;
$this->howlong = $session->howlong;

If it is global object use global $session; before accessing it.

時窥 2024-10-13 04:46:54

看起来问题是 get() 中的 if 后面缺少大括号。

当我在 list($h,$min,$sec)=explode(":",date("H:i:s",$diff)); 之后添加大括号时,代码运行没有错误。

It looks like the problem is the missing brace after the if in get().

When I add a brace after list($h,$min,$sec)=explode(":",date("H:i:s",$diff));, the code runs without an error.

绝影如岚 2024-10-13 04:46:54

请关闭类}操作符missiong

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;

Please close class } operator missiong

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;
暗藏城府 2024-10-13 04:46:54

你可以试试这个:

include("include/session.php");

    class createcountdown
        {
        public $start;
        public $howlong;
        public $session; // add 
        public function get(){
       // $this->start = $session->start; // $session->start Returns data from Mysql: 0000-00-00 00:00:00
         $this->start = $this->session->start; // change here
        // $this->howlong = $session->howlong; // $session->howlong Returns data from Mysql: 300
        $this->howlong = $this->session->howlong; // change here

        $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();
    $obj->session = $session // which is globaly define
    $result = $obj->get();
    echo $result;

you can try this :

include("include/session.php");

    class createcountdown
        {
        public $start;
        public $howlong;
        public $session; // add 
        public function get(){
       // $this->start = $session->start; // $session->start Returns data from Mysql: 0000-00-00 00:00:00
         $this->start = $this->session->start; // change here
        // $this->howlong = $session->howlong; // $session->howlong Returns data from Mysql: 300
        $this->howlong = $this->session->howlong; // change here

        $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();
    $obj->session = $session // which is globaly define
    $result = $obj->get();
    echo $result;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文