473,238 Members | 3,787 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,238 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 1954
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.