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(__METHOD__);
throw $ce;
}
return $ch_data;
}
protected function TransformTemplate($ch_func, $sy_par = '')
{
// code skipped for readability
}
public function Meta()
{
$this->TransformTemplate(__FUNCTION__);
}
public function Navi()
{
$this->TransformTemplate(__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($xml = '', $xsl = '', $par = '', $inc = '', $ttl = '')
# function __construct($ttl = '', $inc = '', $xml = '', $xsl = '', $par = '')
{
# invoke properties
$this->setTitel($ttl);
$this->setQuellen($inc, $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($value))
{
$emsg = "Ungültiger Variablentyp für \"" . $key . "\" (" . gettype($value) . ")";
throw new InitException(11, __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(20, __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_Titel)
{
# set any empty value to empty string
# error out if value is not a string
if (empty($sy_Titel))
{
$sy_Titel = '';
}
elseif (!is_string($sy_Titel))
{
throw new InitException(11, __METHOD__, "Fehler bei der WDDX-Deserialisierung, falscher Variablentyp (" . gettype($sy_Titel) . "). 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($this->inc, $this->xml, $this->xsl, $this->par);
$this->setTitel($this->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_type, $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]