Need Help understanding Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    Need Help understanding Error

    Hi,

    I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means:

    Error:
    Fatal error: Can't use method return value in write context in "output.php " on line 142 (line 12 in snippet)

    the error is caused by this call:
    [PHP]empty($inSeite_ inp->getValue('PAR_ NAME'))[/PHP]
    method definition see second snippet, lines 142 to 166

    EDIT: the method causes this error only when used inside empty().

    can anyone explain to me, what the cause/meaning of this error is?

    thanks

    output.php
    [PHP]abstract class aHTML
    {
    protected $inTpl_inp = NULL;

    protected function Transform(Seite $inSeite_inp, $sy_par = '')
    {
    # get filenames from Template
    $rfDat_xml = $inSeite_inp->getValue('XML' );
    $rfDat_xsl = $inSeite_inp->getValue('XSL' );

    # set parameter correctly
    $mp_param = empty($inSeite_ inp->getValue('PAR_ NAME')) ? NULL : $inSeite_inp->getValue('PAR_ ARRAY', $sy_par); // line 142

    # start XSLT
    $inXSLT_process = new XSLTransform();

    try {
    $ch_data = $inXSLT_process->Process($rfDat _xml, $rfDat_xsl, $mp_param);
    }
    # handling incomplete
    catch (ProcException $pe)
    {
    ErrorLog::add(% some-variables%);
    return $pe;
    }
    catch (CheckException $ce)
    {
    ErrorLog::add(% some-variables%);
    $ce->setMethod(__ME THOD__);
    throw $ce;
    }

    return $ch_data;
    }

    protected function TransformTempla te($ch_func, $sy_par = '')
    {
    // code skipped for readability
    }

    public function Meta()
    {
    $this->TransformTempl ate(__FUNCTION_ _);
    }

    public function Navi()
    {
    $this->TransformTempl ate(__FUNCTION_ _);
    }

    abstract public function Titel();
    abstract public function Inhalt();
    }[/PHP]

    class Seite
    [PHP]class Seite
    {
    protected $titel = '';
    protected $inc = '';
    protected $xml = '';
    protected $xsl = '';
    protected $par = '';

    /**
    * set properties, checks will be performed here
    *
    * @ttl title value
    * default: ''
    *
    * @inc name of static include file
    * default: ''
    *
    * @xml name of input xml file
    * default: ''
    *
    * @xsl name of XSLT stylesheet used on xml file
    * default: ''
    *
    * @par XSLT parameter name
    */
    function __construct($xm l = '', $xsl = '', $par = '', $inc = '', $ttl = '')
    # function __construct($tt l = '', $inc = '', $xml = '', $xsl = '', $par = '')
    {
    # invoke properties
    $this->setTitel($ttl) ;
    $this->setQuellen($in c, $xml, $xsl, $par);
    }

    /**
    * save values to properties. check if every property is a string
    * if neither the include file nor the XSLT stylesheet are defined
    * throw an exception (xml has a default value in the xml's DTD).
    * set all empty values to '' (empty string).
    *
    * @inc name of static include file
    *
    * @xml name of input xml file
    *
    * @xsl name of XSLT stylesheet used on xml file
    *
    * @par XSLT parameter name
    *
    * @thrown InitException, when a value is not a string, due to
    * - wrong stylesheet
    *
    * @thrown InitException, when one of the mandatory properties
    * (xsl, inc) is empty, due to
    * - wrong stylesheet
    */
    private function setQuellen($inc , $xml, $xsl, $par)
    {
    # prepare for check loop
    # keys must be the names of the properties
    $source = array(
    'inc' => $inc,
    'xml' => $xml,
    'xsl' => $xsl,
    'par' => $par
    );

    # change that for the case I use multiple parameters
    # ('par' will be array then)
    foreach ($source as $key => $value)
    {
    # error out if not-empty values are not strings
    if (!empty($value) and !is_string($val ue))
    {
    $emsg = "Ungültiger Variablentyp für \"" . $key . "\" (" . gettype($value) . ")";
    throw new InitException(1 1, __METHOD__, $emsg);
    }

    # convert empty values to empty string
    # set properties from array-keys
    $this->$key = (empty($value)) ? '' : $value;
    }

    # error out if either xsl or include file is missing
    # this state is forbidden by DTD (if used)
    if (empty($inc) and empty($xsl))
    {
    throw new InitException(2 0, __METHOD__, "Eine notwendige Datei wurde nicht eingetragen. XML-Datei überprüfen!");
    }

    }

    /**
    * set titel-property, use empty string for empty values
    *
    * @sy_Titel new title value to be set
    *
    * @thrown InitException, when title is not a string
    * possible reasons.
    * - wrong stylesheet (WDDX)
    * - wrong manual input (new Seite)
    */
    private function setTitel($sy_Ti tel)
    {
    # set any empty value to empty string
    # error out if value is not a string
    if (empty($sy_Tite l))
    {
    $sy_Titel = '';
    }
    elseif (!is_string($sy _Titel))
    {
    throw new InitException(1 1, __METHOD__, "Fehler bei der WDDX-Deserialisierun g, falscher Variablentyp (" . gettype($sy_Tit el) . "). XSL-Datei überprüfen!");
    }

    $this->titel = $sy_Titel;
    }

    /**
    * same as in __construct(), but properties are used as input
    * (i.e. the properties are redefined)
    */
    public function checkProps()
    {
    # error will be thrown if properties were deserialized
    # with a bad data type
    $this->setQuellen($th is->inc, $this->xml, $this->xsl, $this->par);
    $this->setTitel($th is->titel);
    }

    /**
    * returns a keyword chosen property
    * a XSLT parameter array can be returned as well if the value is given
    *
    * @fch_type keyword to get a property
    * ::= ( "TITEL" | "QUELLE" | "INCLUDE" | "XML" | "XSL" |
    * "PAR_NAME" | "PAR_ARRAY" )
    * QUELLE returns an array of all properties but titel
    * PAR_ARRAY returns an array suited for XSLTransform
    *
    * @si_parvalue value of the XSLT parameter
    * default: ''
    */
    public function getValue($fch_t ype, $si_parvalue = '')
    {
    # return properties (write protected)
    # parameter may be returned as array (needed for XSLT)
    // PHP 4 used xslt_process(), parameters had to be passed as NULL or
    // array. out of convenience this was kept since it is easier to pass
    // one array than lots of key-value pairs.
    switch ($fch_type)
    {
    case "TITEL":
    return $this->titel;
    case "QUELLE":
    return array('inc' => $this->inc, 'xml' => $this->xml, 'xsl' => $this->xsl, 'par' => $this->par);
    case "INCLUDE":
    return $this->inc;
    case "XML":
    return $this->xml;
    case "XSL":
    return $this->xsl;
    case "PAR_NAME":
    return $this->par;
    case "PAR_ARRAY" :
    return array($this->par => $si_parvalue);
    }
    }
    }[/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Dormilich.

    The error is somewhat cryptic, as it has to do with the way empty() checks to see if a value is defined. You will notice similar issues with isset().

    The quick solution is to assign the return value of the method to a variable:

    [code=php]
    $temp = $inSeite_inp->getValue('PAR_ NAME');
    if( empty($temp) )
    [/code]

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Thanks pbmods,

      the solution is working fine. Though I'm still interested why (is there any article or anything, where I can read about that?).

      Comment

      Working...