Call to a member function on a non-object,分不够再加
程序员文章站
2023-12-31 21:24:52
...
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的几位都说的很明白了。
相关文章
相关视频
- 逃离伪PHP软件工程师应该做的事
- php兑现自动获取生成关键词功能
- 这个SQL里的函数是mysql函数还是php函数...
- Oauth2.0开发 为什么子要提交access_...
- Call to a member functio...
推荐阅读
-
Call to a member function on a non-object,分不够再加
-
PHP对象编程有关问题,Call to a member function hello() on a non-object
-
PHP对象编程有关问题,Call to a member function hello() on a non-object
-
求大神纠错,多谢!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