Php 意外的T_字符串,但在哪里?

Php 意外的T_字符串,但在哪里?,php,prestashop,Php,Prestashop,我正在做一个prestashop模块(我昨天发布了另一个问题)。现在我觉得PHP有问题了。每次它都告诉我行if($same\u puente==false或$same\u patilla==false).Parse error:syntax error,该行中出现意外的T\u字符串 <?php if (!defined('_PS_VERSION_')) exit; class glassOptics extends Module { /* @var boolean er

我正在做一个prestashop模块(我昨天发布了另一个问题)。现在我觉得PHP有问题了。每次它都告诉我行
if($same\u puente==false或$same\u patilla==false).
Parse error:syntax error,该行中出现意外的T\u字符串

<?php

if (!defined('_PS_VERSION_'))
    exit;

class glassOptics extends Module
{
    /* @var boolean error */
    protected $_errors = false;

    /* @var boolean puente */
    public $same_puente = false;

    /* @var boolean patilla */
    public $same_patilla = false;

    /* @var boolean altura cristal */
    public $same_altura_cristal = false;

    /* @var boolean ancho cristal */
    public $same_ancho_cristal = false;

    public function __construct()
    {
        $this->name = 'glassOptics';
        $this->tab = 'front_office_features';
        $this->version = '1.0';
        $this->author = 'Víctor Martín';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('glassOptics');
        $this->description = $this->l('Módulo para Ópticas, de filtrado de gafas compatibles para cada cliente.');
    }

    public function install()
    {
        if (!parent::install() OR
            !$this->glopticasCustomerDB('add') OR
            !$this->glopticasProductDB('add') OR
            !$this->glopticasProductLangDB('modify') OR         
            !$this->registerHook('hookActionProductListOverride') OR            
            !$this->registerHook('DisplayAdminProductsExtra') OR            
            !$this->registerHook('ActionProductUpdate'))
            return false;
        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall() OR !$this->glopticasCustomerDB('remove') OR !$this->glopticasProductDB('remove'))
            return false;
        return true;
    }


    public function glopticasCustomerDB($method)
    {
        switch ($method) {
            case 'add': 

                $decimal_zero = '0.000000';
                $decimal_zero = mysql_real_escape_string($decimal_zero);

                $sql = 'CREATE TABLE IF EXISTS `'._DB_PREFIX_.'customer_optics_data` (
                `id_customer` int(10) UNSIGNED NOT NULL,
                `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.'
                ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

                break;

            case 'remove':
                $sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_ . 'customer_optics_data`';
                break;
        }

        if(!Db::getInstance()->Execute($sql))
            return false;
        return true;
    }

    public function glopticasProductDB($method)
    {
        switch ($method) {
            case 'add': 

                $decimal_zero = '0.000000';
                $decimal_zero = mysql_real_escape_string($decimal_zero);

                $sql = 'CREATE TABLE IF EXISTS `'._DB_PREFIX_.'product_optics_data` (
                `id_product` int(10) UNSIGNED NOT NULL,
                `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.',
                `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.'
                ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

                break;

            case 'remove':
                $sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_ . 'product_optics_data`';
                break;
        }

        if(!Db::getInstance()->Execute($sql))
            return false;
        return true;
    }


    public function glopticasProductLangDB($method)
    {
        switch ($method) {
            case 'modify':  

                $decimal_zero = '0.000000';
                $decimal_zero = mysql_real_escape_string($decimal_zero);

                $sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'product_lang '
                .'ADD `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
                .'ADD `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.''
                .') ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

                break;

        }

        if(!Db::getInstance()->Execute($sql))
            return false;
        return true;
    }

    public function hookActionProductListOverride($params)
    {
        $customer_settings = glassOpticsHelperClass::getCustomerSettings($this->context->customer);

        if (!is_null($customer_settings)) {
            // Inform the hook was executed
            $params['hookExecuted'] = true;

            // Filter products here, you are now overriding the default
            // functionality of CategoryController class.
            // You can see blocklayered module for more details.

            if ((isset($this->context->controller->display_column_left) && !$this->context->controller->display_column_left)
            && (isset($this->context->controller->display_column_right) && !$this->context->controller->display_column_right))
            return false;

            global $smarty;
            if (!Configuration::getGlobalValue('PS_LAYERED_INDEXED'))
                return;

            $sql_cat = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'layered_category WHERE id_category = '.(int)Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))).'
                AND id_shop = '.(int) Context::getContext()->shop->id;
            $categories_count = Db::getInstance()->getValue($sql_cat);

            if ($categories_count == 0)
                return;

            // List of product to overrride categoryController
            $params['catProducts'] = array();
            $selected_filters = $this->getSelectedFilters();
            $filter_block = $this->getFilterBlock($selected_filters);
            $title = '';

            if (is_array($filter_block['title_values']))
                foreach ($filter_block['title_values'] as $key => $val)
                    $title .= ' > '.$key.' '.implode('/', $val);

            $smarty->assign('categoryNameComplement', $title);
            $this->getProducts($selected_filters, $params['catProducts'], $params['nbProducts'], $p, $n, $pages_nb, $start, $stop, $range);
            // Need a nofollow on the pagination links?
            $smarty->assign('no_follow', $filter_block['no_follow']);

            filterProductsByConditions($customer_settings, $params['nbProducts']);


        }
    }

    private static function filterProductsByConditions($customer_settings, $product_collection) {
        if(!is_null($product_collection)){

            foreach ($product_collection as $product){
                $product_settings = glassOpticsHelperClass::getProductSettings($product);

                if(!is_null($product_settings)){

                    if(!is_null($product_settings->puente) AND !is_null($customer_settings->puente)){
                        $same_puente = (($product_settings->puente == $customer_settings->puente) ? true : false);
                    }else{
                        $same_puente = false;
                    }

                    if(!is_null($product_settings->patilla) AND !is_null($customer_settings->patilla)){
                        $same_patilla = (($product_settings->patilla == $customer_settings->patilla) ? true : false);
                    }else{
                        $same_patilla = false;
                    }

                    if(!is_null($product_settings->altura_cristal) AND !is_null($customer_settings->altura_cristal)){
                        $same_altura_cristal = (($product_settings->altura_cristal == $customer_settings->altura_cristal) ? true : false);
                    }else{
                        $same_altura_cristal = false;
                    }

                    if(!is_null($product_settings->ancho_cristal) AND !is_null($customer_settings->ancho_cristal)){
                        $same_ancho_cristal = (($product_settings->ancho_cristal == $customer_settings->ancho_cristal) ? true : false);
                    }else{
                        $same_ancho_cristal = false;
                    }

                    if($same_puente === false OR $same_patilla === false){
                        unset($product_collection[$product]);
                    }
                }
            }
            return $product_collection;
        }else{
            return $product_collection;
        }
    }
}

$sql
语句中有一个额外的结束括号:
')ENGINE='.\u MYSQL\u ENGINE'.

$sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'product_lang '
.'ADD `dioptrias_izquierdo` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `dioptrias_derecho` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `puente` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `patilla` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `altura_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.','
.'ADD `ancho_cristal` decimal(20,6) NOT NULL DEFAULT '.$decimal_zero.''
.') ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';
你的问题是:

foreach ($product_collection as $product){
    ...
    unset($product_collection[$product]);
}
对于数组的get元素,必须使用
$key

foreach ($product_collection as $key => $product){
    ...
    unset($product_collection[$key]);
}

因为
$product
是数组元素的值,但不是键。

如果删除该行,它会改变什么吗?