Call to a member function on a non-object,分不够再加
程序员文章站
2022-05-01 10:41:23
...
Call to a member function on a non-object,急在线等,分不够再加
calss cart {
function get_item()
{
if(!empty($_SESSION[ 'cart '])&&is_array($_SESSION[ 'cart ']))
{
return $_SESSION[ 'cart '];
}
else
{
$_SESSION[ 'cart ']=array();
return $_SESSION[ 'cart '];
}
}
}
$data=$cart-> get_item();
PHP Version 4.3.11,PHP Version 4.4.4 下测试出错,Call to a member function on a non-object
PHP Version 4.4.6, PHP Version 5.1.2 下测试正常,可以打印出print_r($data);
------解决方案--------------------
你最好还是 new 一个实例比较好.
------解决方案--------------------
能正常就怪了
class cart {
function get_item()
{
if(!empty($_SESSION[ 'cart '])&&is_array($_SESSION[ 'cart ']))
{
return $_SESSION[ 'cart '];
}
else
{
$_SESSION[ 'cart ']=array();
return $_SESSION[ 'cart '];
}
}
}
$cart = new cart();
$data = $cart-> get_item();
------解决方案--------------------
Call to a member function on a non-object
===========================================
呼叫空对象的成员函数.
"non-object ",说明对象未实例化,即是没有new过.
------解决方案--------------------
嗯,liyong98847()说的有道理.你检查一下php4下的php.ini里的register_globals是否为off,如果是on的话,$_SESSION[ 'cart ']与$cart是等效的.
在register_globals=on的情况下:
==============================================
$cart = new cart();//在cart类里改动了$_SESSION[ 'cart ']的值,也相当与改了$cart的值
$data=$cart-> get_item();//$cart已经被改动,造成Call to a member function on a non-object
你可以换个变量名试试,如果没发生错误,证明就是以上所说的问题
====================================================
$c = new cart();
$data=$c-> get_item();
------解决方案--------------------
LS的几位都说的很明白了。
calss cart {
function get_item()
{
if(!empty($_SESSION[ 'cart '])&&is_array($_SESSION[ 'cart ']))
{
return $_SESSION[ 'cart '];
}
else
{
$_SESSION[ 'cart ']=array();
return $_SESSION[ 'cart '];
}
}
}
$data=$cart-> get_item();
PHP Version 4.3.11,PHP Version 4.4.4 下测试出错,Call to a member function on a non-object
PHP Version 4.4.6, PHP Version 5.1.2 下测试正常,可以打印出print_r($data);
------解决方案--------------------
你最好还是 new 一个实例比较好.
------解决方案--------------------
能正常就怪了
class cart {
function get_item()
{
if(!empty($_SESSION[ 'cart '])&&is_array($_SESSION[ 'cart ']))
{
return $_SESSION[ 'cart '];
}
else
{
$_SESSION[ 'cart ']=array();
return $_SESSION[ 'cart '];
}
}
}
$cart = new cart();
$data = $cart-> get_item();
------解决方案--------------------
Call to a member function on a non-object
===========================================
呼叫空对象的成员函数.
"non-object ",说明对象未实例化,即是没有new过.
------解决方案--------------------
嗯,liyong98847()说的有道理.你检查一下php4下的php.ini里的register_globals是否为off,如果是on的话,$_SESSION[ 'cart ']与$cart是等效的.
在register_globals=on的情况下:
==============================================
$cart = new cart();//在cart类里改动了$_SESSION[ 'cart ']的值,也相当与改了$cart的值
$data=$cart-> get_item();//$cart已经被改动,造成Call to a member function on a non-object
你可以换个变量名试试,如果没发生错误,证明就是以上所说的问题
====================================================
$c = new cart();
$data=$c-> get_item();
------解决方案--------------------
LS的几位都说的很明白了。
相关文章
相关视频
- 详解win10下PHP的安装配置(以php5.6为...
- php Swoole实现毫秒定时计划任务(详解)
- 【DTM】PHP协程客户端v0.1 beta版本发...
- 一文详解Windows和Linux环境下怎么安装配...
- Call to a member function...
推荐阅读
-
求大神纠错,多谢!Fatal error: Call to a member function query() on a non-object
-
Call to a member function fetch() on a non-object异常
-
Fatal error: Call to a member function fetch_array() on a non-object in 62 line
-
php中出现“Call to a member function Execute() on a non-object”的有关问题
-
Fatal error: Call to a member function fetch_array() on a non-object in 62 line
-
PHP对象编程有关问题,Call to a member function hello() on a non-object
-
【】Fatal error: Call to a member function * on a non-object
-
Fatal error: Call to a member function fetch_array() on a non-object in 62 line,该如何处理
-
PDO——Call to a member function query() on a non-object
-
Fatal error: Call to a member function fetch_array() on a non-object 错误