Irf*_*fan 24 php wordpress session session-variables
我收到一个错误,完整的错误是:
Fatal error: authnet_cart_process() [<a href='function.authnet-cart-process'>function.authnet-cart-process</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "AuthnetCart" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /home/golfetc/public_html/wp-content/plugins/sccp-2.4.0/authnet_functions.php on line 1266
Run Code Online (Sandbox Code Playgroud)
我正在使用会话来存储购物车对象,并在稍后的某个时候获取它.authnetCart基本上是cart对象的类.
// Check cart in session
if(isset($_SESSION['AUTHNET_CART'])) {
// Get cart from session
$authnetCart = $_SESSION['AUTHNET_CART'];
foreach($authnetCart->getCartItems() as $item) { // Line#1266
if ($item->getItemId() == $subscription_details->ID ) {
$addNewItem = false;
break;
}
}
......
Run Code Online (Sandbox Code Playgroud)
您可以在第1266行看到,代码不允许我访问其方法.任何帮助将受到高度赞赏.谢谢
Vol*_*oka 43
你需要include/ require你的类PHP 之前 session_start()一样
include PATH_TO_CLASS . 'AuthnetClassFilename.php';
session_start();
if (isset($_SESSION['AUTHNET_CART'])) {
//...
}
Run Code Online (Sandbox Code Playgroud)
看来您的答案就在错误消息中。
在反序列化 AUTHNET_CART 之前,请包含定义它的类。手动或使用自动装载机。
include PATH_TO_CLASS . 'AuthnetClassFilename.php';
if(isset($_SESSION['AUTHNET_CART'])) {//...
Run Code Online (Sandbox Code Playgroud)
看来您实际上也没有对其进行反序列化(我假设在将其填充到会话中之前已对其进行了序列化?)
if(isset($_SESSION['AUTHNET_CART'])) {
// Get cart from session
/** UNSERIALIZE **/
$authnetCart = unserialize($_SESSION['AUTHNET_CART']);
foreach($authnetCart->getCartItems() as $item) { // Line#1266
if ($item->getItemId() == $subscription_details->ID ) {
$addNewItem = false;
break;
}
}
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32818 次 |
| 最近记录: |