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

Dmitry Dulepov dima at spamcop.net
Mon Mar 20 15:16:02 CET 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

Franz Holzinger wrote:
> 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.

Depends on where you use it. I had extensions in mind. Internal
functions may return errors. Upper functions decide what to do.
Sometimes it is safe to ignore. But for many cases your approach is
better. I would just modify it a bit:

> 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]) {

if ($contentTmp) {

Since it returns true or false.

In fact there could be even better solution (I do not really like arrays
because I never can remember what is in [0] or [1]):

class ErrorObj {
	var	$errorCode;
	var	$errorText;
	var	$errorInfo;	// anything error-specific
}

and pass this object. Function should return result or false. If false
is returned, this object says what happended:

function foo($bar, &$errorObj) {
	$t = time();
	if ($t & 1) {
		$errorObj.errorCode = 12345;	// any whatever applies
		$errorObj.errorText = 'Random unpredictable error';
		$errorObj.errorInfo = $t;	// any whatever applies
		return false;
	}
	return new MyOtherClass($bar);
}

$errorObj = t3lib_div::makeInstance('t3lib_errorObj');
if (false === ($result = foo(1, $errorObj))) {
	$this->content .= $errorObj.errorText;
}
else {
	$this->content = $result->doMyOperation();
}

Dmitry.
- --
"It is our choices, that show what we truly are,
far more than our abilities." (A.P.W.B.D.)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)

iD8DBQFEHrkiRVcYnKJ8N6kRAtQzAKDQBbbDwOF+o2eWJWf1v9N0tzB8WQCeNU8M
I4WypIly8BOj54gI8Eoub/0=
=UK8S
-----END PGP SIGNATURE-----



More information about the TYPO3-team-core mailing list