2015-04-14 8 views
5

sto ottenendo questo errore in un'applicazione che sto migrando da SF2.0.x a SF2.7:errore di compilazione: Impossibile utilizzare isset() sul risultato di un'espressione

[1] Symfony\Component\Debug\Exception\FatalErrorException: Compile Error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) 
    at n/a 
     in /var/www/html/reptooln_admin/app/cache/dev/twig/68/7f/63589dd3687cb849dd68e6b6c10aa99eda1d82f95a5f3ac52a864d200499.php line 39 

I don' so cosa sta fallendo o come risolvere questo problema, quindi ho bisogno di qualche consiglio. Questa è la linea al file di cache in cui viene riportato lo Stacktrace:

if ((((empty((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context, "form_action"))) == true) || (isnull((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context, "form_action"))) == true)) || (isset((isset($context["form_action"]) ? $context["form_action"] : $this->getContext($context, "form_action"))) == false))) { 
       echo " "; 
       $context["form_action"] = ""; 
       echo " "; 

Quello che ho questo TwigExtension:

class PDOneTwigExtension extends \Twig_Extension 
{ 
    public function getFilters() 
    { 
     return array(
      'var_dump' => new \Twig_Filter_Function('var_dump'), 
      'empty' => new \Twig_Filter_Function('empty', array($this, 'is_empty')), 
      'isset' => new \Twig_Filter_Function('isset', array($this, 'is_set')), 
      'isnull' => new \Twig_Filter_Function('isnull', array($this, 'is_null')), 
      'ucfirst' => new \Twig_Filter_Function('ucfirst', array($this, 'uc_first')), 
      'ucwords' => new \Twig_Filter_Function('ucwords', array($this, 'uc_words')), 
      'count' => new \Twig_Filter_Function('count', array($this, 'co_unt')), 
      'sizeof' => new \Twig_Filter_Function('sizeof', array($this, 'size_of')), 
      'concat' => new \Twig_Filter_Function('concat', array($this, 'concat')), 
      'in_array' => new \Twig_Filter_Function('in_array', array($this, 'inarray')), 
      'array' => new \Twig_Filter_Function('array', array($this, 'array_')), 
      'add_to_array' => new \Twig_Filter_Function('add_to_array', array($this, 'add_to_array')), 
      'replace' => new \Twig_Filter_Function('replace', array($this, 'replace')), 
      'htmlentitydecode' => new \Twig_Filter_Function('htmlentitydecode', array($this, 'htmlentitydecode')) 
     ); 
    } 

    public function is_empty($sentence) 
    { 
     return empty($sentence) ? true : false; 
    } 

    // rest of methods goes here 

    public function getName() 
    { 
     return 'pdone_twig_extension'; 
    } 
} 

e sto usando al modello come segue:

{% if form_action|empty == true or form_action|isnull == true or form_action|isset == false %} {% set form_action = '' %} {% endif %} 

Dove potrebbe esserci il problema qui? Qualche consiglio?

+0

Quello che stai facendo in pratica non v'è 'isset ($ this-> getContext (args) == true)', che naturalmente è espressione – adeneo

+0

@adeneo qualche soluzione? – ReynierPM

+0

Uhm, forse l'ho interpretato male, mi sono confuso con tutta la follia ternaria annidata, ma la soluzione è ovviamente non usare isset su un'espressione? – adeneo

risposta

16

Da documentation:

isset() only works with variables as passing anything else will result in a parse error.

Lei non è passare direttamente a una variabile isset(). Quindi è necessario prima calcolare il valore, assegnarlo a una variabile e quindi passarlo a isset().

Per esempio, quello che stai facendo in questo momento è qualcosa di simile:

if(isset($something === false)) { } // throws a parse error, because $something === false is not a variable 

Quello che dovete fare è invece:

$something = false; 
if(isset($something)) { ... } 
+0

Sì, ho appena capito, sto provando a sistemare il codice – ReynierPM

0

Perché fai così tanto di codice inutile?

perché non solo:

{% if form_action|empty == true %} {% set form_action = '' %} {% endif %} 
+0

Non ero io e ho solo migrato il vecchio codice a uno nuovo e ho risolto tutti i problemi – ReynierPM

+0

@ReynierPM prima, rimuovi questo codice "inutile";) – jamek

Problemi correlati