[TYPO3-core] return value of t3lib_div::resolveSheetDefInDS()

Franz Holzinger franz at fholzinger.com
Mon Mar 20 15:05:06 CET 2006


Dmitry Dulepov a écrit :

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hi!
>
>Martin Kutschker wrote:
>  
>
>>This is the description of the return value:
>>
>>"An array with two num. keys: key0: The data structure is returned in this key (array) UNLESS an error happend in which case an error string is returned (string). key1: The used sheet key value!"
>>
>>Cannot say I like this very much. Returning FALSE on error is a PHP practice. Returning strings just looks awful.
>>
>>We had the discussion before with FALSE and -1. Now it's strings. And all this only because of this stupid PHP5 errors... Ok, i fact it's an error in the calling code.
>>    
>>
>
>I usually use:
>
>function foo($bar, &$error) {
>	if (errorHappens($bar)) {
>		$error = 'Error happened!';
>		return false;
>	}
>	return true;
>}
>
>Drawback: cannot use default values if $error is the last parameter.
>
>
>  
>

A string must be used in the case when usually a Conten element should
be returned. It would be of more help to have an error_code array as an
additional parameter. The first with the reference to a language text
and the others as indices (parameters) to it.

function foo($bar, &$error_code) {
	if (errorHappens($bar)) {
		$error_code[0] = 'no_subtemplate';
		$error_code[1] = $templateArea;
		$error_code[2] = $this->conf['templateFile'];
		return false;
	}
	return true;
}


$contentTmp = $this->foo($bar, $error_code);
if ($error_code[0]) {
    $messageArr = array();
    $i = 0;
    foreach ($error_code as $key => $indice) {
    if ($key == 0) {
        $messageArr =  explode('|', $message = $this->pi_getLL($indice));
        $contentTmp.=$this->pi_getLL('tt_products').' '.$messageArr[0];
    } else {
        $contentTmp.=$indice.$messageArr[$i];
    }
    $i++;
    }
}
if ($contentTmp == 'error') {
    $content .=
$this->pi_displayHelpPage($this->cObj->fileResource('EXT:'.TT_PRODUCTS_EXTkey.'/template/products_help.tmpl'));
    unset($this->errorMessage);
    break; // while
} else {
    $content.=$contentTmp;
}



- Franz





More information about the TYPO3-team-core mailing list