Call to a member function on a non-object,分不够再加
程序员文章站
2024-01-21 13:40:04
...
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教程
- 模拟OICQ的实现思路和核心程序三转--建议加入精...
- php新手入门经验谈_PHP教程
- 关于中英数字混的字串符分割问题_PHP教程
- Call to a member function...
上一篇: php求圆周率的简单实现方法 原创,fontcolor
下一篇: sqlserver锁机制
推荐阅读
-
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
-
php中出现“Call to a member function Execute() on a non-object”的有关问题
-
Fatal error: Call to a member function fpage() on a non-object
-
Fatal error: Call to a member function fpage() on a non-object解决方案
-
Fatal error: Call to a member function get() on a non-object
-
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