Re: Inline typecasting / typehinting for classes and interfaces

From: Date: Wed, 15 Aug 2012 08:15:04 +0000
Subject: Re: Inline typecasting / typehinting for classes and interfaces
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-62167@lists.php.net to get a copy of this message
What's wrong with instanceof? You can then throw fatal error if you want, it's just two lines: if(!($foo instanceof Bar)) { trigger_error(E_USER_ERROR, "Wrong foo!"); }
That's 3 lines on top of the line where you assign the value, and you forgot the 4th line for the IDE: ----- /* @var $foo Bar */ $foo = expression(); if(!($foo instanceof Bar)) { trigger_error(E_USER_ERROR, "Wrong foo!"); } ----- Versus this: ---- Bar $foo = expression(); ---- And assignment is a kinda common operation. So I hope you can see what's wrong with it now. Stan

« previous php.internals (#62167) next »