Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.php > #3886
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | de.comp.lang.php |
| Subject | Re: return types |
| Date | 2016-04-19 20:24 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1882669.YLIovkB3xS@PointedEars.de> (permalink) |
| References | <1t56fced94i14b9n3e8%sfroehli@Froehlich.Priv.at> <3243755.WBM996tjSl@PointedEars.de> <dm7lpsFpt1jU1@mid.individual.net> <6322257.QELA2EPoA3@PointedEars.de> <ft570c14e6i64can3e8%sfroehli@Froehlich.Priv.at> |
Stefan Froehlich wrote:
> Nicht direkt mit return types, aber mit dem artverwandten
> strict_types zu tun hat folgende Kuriosität: Ableiten einer
> benutzerspezifischen Exception-Klasse, bei der die Fehlercodes
> so, wie bei der nativen Klasse, optional sein sollen:
>
> #v+
> declare(strict_types=1);
>
> class Exception_Foo extends Exception {
Bezeichner von Exception-Klassen sollten auf “Exception” oder “Error”
*enden* und benutzerdefinierte Exception-Klassen sollten in einem eigenen
Namespace deklariert werden.
> public function __construct($message, $code=NULL) {
> [some magic]
> parent::__construct($message, $code);
> }
> }
>
> throw new Exception_foo('Test');
> #v-
>
> Tja, *so* geht das jedenfalls nicht. Mit Defaultwert 0 kommt man
> weiter, erreicht aber nicht das, was eigentlich angestrebt worden
> ist.
$ php -r '
class FooException extends Exception
{
public function __construct ($message, $code=NULL)
{
call_user_func_array("parent::__construct", func_get_args());
// [some magic]
}
}
try
{
throw new FooException("bla");
}
catch (Exception $e)
{
echo $e->getCode() . "\n";
}
'
0
> Da braucht es wohl noch ein paar Nachbesserungen.
Sonst schon, da nicht unbedingt.
--
PointedEars
Zend Certified PHP Engineer
<http://www.zend.com/en/yellow-pages/ZEND024953> | Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to de.comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar
return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-03-31 09:35 +0000
Re: return types k@rl.pflaesterer.de (Karl Pflästerer) - 2016-03-31 12:42 +0200
Re: return types "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-03-31 14:16 +0200
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-04-15 06:37 +0000
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-06-22 08:48 +0000
Re: return types "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-22 12:25 +0200
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-06-22 14:49 +0000
Re: return types "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-22 17:47 +0200
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-06-23 08:23 +0000
Re: return types "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-07-02 01:03 +0200
Re: return types Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-31 21:40 +0200
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-04-01 16:26 +0000
Re: return types "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-04-02 19:23 +0200
Re: return types Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-02 20:36 +0200
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-04-11 21:18 +0000
Re: return types Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-02 20:33 +0200
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-04-11 21:32 +0000
Re: return types Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-19 20:24 +0200
Re: return types Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2016-04-20 07:05 +0000
Re: return types Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-21 02:55 +0200
csiph-web