473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Need Help understanding Error

Dormilich
8,658 Expert Mod 8TB
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]
Nov 20 '08 #1
2 1959
pbmods
5,821 Expert 4TB
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:

Expand|Select|Wrap|Line Numbers
  1. $temp = $inSeite_inp->getValue('PAR_NAME');
  2. if( empty($temp) )
  3.  
Nov 21 '08 #2
Dormilich
8,658 Expert Mod 8TB
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?).
Nov 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
2
by: den.NET | last post by:
well,i use visual c++.NET 2003.i am organizing a windows form application.i attached a form shape to tell my problem( please coppy this url and have a look :...
1
by: Charlie Brookhart | last post by:
I am not understanding what the following error message is saying: An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll Additional information:...
17
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms...
2
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
3
by: Greg Corradini | last post by:
Hello, I'm trying to perform a simple insert statement into a table called Parcel_Test (see code below). Yet, I get an error message that I've never seen before (see traceback below). I've tried...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
9
by: Daniel Smedegaard Buus | last post by:
Hey all :) I was wondering about the $error_types (I particularly notice the 's' suffix when reading the manual) parameter for 'set_error_handler()': Can be used to mask the triggering of the...
4
by: Uriel88 | last post by:
Hello, I am working with developing an application that uses the Netmon 3.2 API. Currently they have a PInvoke wrapper to access unmanaged C++ DLL functions. Basically what I am attempting to do...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.