Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 致命错误:对中的非对象调用成员函数getObject()_Php_Database_Phpmyadmin - Fatal编程技术网

Php 致命错误:对中的非对象调用成员函数getObject()

Php 致命错误:对中的非对象调用成员函数getObject(),php,database,phpmyadmin,Php,Database,Phpmyadmin,我正在开发一个卡在这个地方的电子商务网站。我已经发布了关于这个错误的SOF帖子,但没有给我太多帮助。目的是根据输入的优惠券代码向客户提供折扣。在这方面,任何人都可以帮我 <?php /** * Consider and apply voucher codes * Types of voucher code * - = FIXED AMOUNT OFF * % = PERCENTAGE OFF * s = SET NEW SHIPPING COST * @param

我正在开发一个卡在这个地方的电子商务网站。我已经发布了关于这个错误的SOF帖子,但没有给我太多帮助。目的是根据输入的优惠券代码向客户提供折扣。在这方面,任何人都可以帮我

<?php
/**
  * Consider and apply voucher codes
  * Types of voucher code
  * - = FIXED AMOUNT OFF
  * % = PERCENTAGE OFF
  * s = SET NEW SHIPPING COST
  * @param voucherCode String
  * @return void
  */
  if(isset($_POST["submit"])){
  $code=$_POST["code"];
  $coupon=new coupon();
  $coupon->Vouchers($code);
  }

  class coupon {

   function Vouchers( $voucherCode )
  {
    //The voucher code value is checked to ensure it is not empty 
    // (as per point 1)
    if( $voucherCode != '' )
    {
      // we need the date, to see if the voucher has expired
      $cts = date('Y-m-d H:i:s');
      $voucherCode=$this->registry;
      $voucher_sql = "SELECT *, if('{$cts}' > expiry, 1, 0)
                        AS expired FROM code
                      WHERE code='{$voucherCode}' LIMIT 1";
                      $voucher_sql=$this->registry;
      $this->registry->getObject('code')->executeQuery( $voucher_sql );
      if( $this->registry->getObject('code')->numRows() == 0 )
      {
        $this->voucher_notice = 'Sorry, the voucher code you entered
            is invalid';
      }
      else
      {
        $voucher = $this->registry->getObject('code')->getRows();
        if( $voucher['active'] == 1 )
        {
          if( $voucher['expired'] == 1 )
          {
            $this->voucher_notice = 'Sorry, this voucher has 
                expired';
            return false;
          }
          else
          {
            // check to see there are some vouchers, and customer
            // has enough in their basket (points 3 and 4)
            if( $voucher['num_vouchers'] != 0 )
            {
              if( $this->cost >= $voucher['min_cost'] )
              {
                $this->discountCode = $voucherCode;
                $this->discountCodeId = $voucher['id'];
                // If the discount operation is a percentage, then
                // the discount value is applied to the basket cost
                // to calculate that percentage. This amount is then
                // deducted from the order cost, giving a "discount
                // value"% discount from the order.
                if( $voucher['operation'] == '%' )
                {
                  $this->cost = $this->
              cost - (($this->cost)/100)*$voucher['amount'];
                  $this->voucher_notice = 'A ' 
                      . $voucher['amount'] 
                      . '% discount has been applied to your order';
                  return true;
                  // If the discount operation is a subtraction, then 
                  // the discount amount from the discount code is 
                  // deducted from the order cost, and the order cost 
                  // is updated to reflect this.
                }
                elseif( $voucher['operation'] == '-' )
                {
                  $this->cost = 
                      $this->cost - $voucher['amount'];
                  $this->voucher_notice = 'A discount of &pound;'
                      . $voucher['amount'] 
                      . ' has been applied to your order';
                  return true;
                  // Finally, if the discount operation is set to s 
                  // then, we set the shipping cost to the discount 
                  // value. This could allow us to set free shipping,
                  // or just reduce shipping costs.
                }
                elseif( $voucher['operation'] == 's' )
                {
                  $this->shipping_cost = $voucher['amount'];
                  $this->voucher_notice = 'Your orders shipping cost
                      has been reduced to &pound;' 
                      . $voucher['amount'];
                  return true;
                }
              }
              else
              {
                $this->voucher_notice = 'Sorry, your order total is 
                    not enough for your order to qualify for this 
                    discount code';
                return false;
              }
            }
            else
            {
              $this->voucher_notice = 'Sorry, this was a limited
                  edition voucher code, there are no more instances
                  of that code left';
              return false;
            }
          }
        }
        else
        {
          $this->voucher_notice = 'Sorry, the vocuher code you
              entered is no longer active';
          return false;
        }
      }
    }
  }
  }
  ?>

看起来错误是

$this->registry->getObject

现在没有地方显示正在注入注册表,所以这就是问题所在。我假设您使用的是一个框架,并且希望这个类能够识别容器,但事实并非如此。因此,插入注册表,或将其安装到构造函数中。

完整的错误消息是什么?这可能是因为您试图对非对象的变量调用方法;这通常是因为漏检和空值。致命错误:在C:\Web Project\xampp\htdocs\shop\a.php第32行的非对象上调用成员函数getObject()。此外,您不检查$凭证是否为对象,只是它不同于“”,这不是一个好的检查。您可以使用is_对象强制执行此检查,或者使用!空。$this->registry或$this->registry->getObject无法返回正确的对象。您应该检查所有这些调用的返回,以了解失败的地方;然后是一个var_转储(get_类($this->registry->getObject('code'))。如果这两个调用中的任何一个抛出一个错误,表示给定的参数不是对象,那么就有了罪魁祸首。然后,您将能够进一步调查调用未返回有效对象的原因。
$this->registry->getObject