Re: Type hinting misunderstood

From: Date: Mon, 07 Jan 2008 03:55:18 +0000
Subject: Re: Type hinting misunderstood
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-34568@lists.php.net to get a copy of this message
On Sun, 2008-01-06 at 19:18 +0200, Giedrius D wrote: > On Jan 6, 2008 5:55 PM, Sam Barrow <sam@sambarrow.com> wrote: > > As I said, this patch is not intended for stuff like $_GET, $_POST, > > database data, etc. It is intended for internal functions to your > > application. > > > > function requireFile(string $file, bool $getOutput = false, array $args > > = array()) > > { > > $obLevel = ob_get_level() ; > > > > ob_start() ; > > > > $return = require_once($file) ; > > > > if ($getOutput) > > { > > $return = ob_get_clean() ; > > } > > else > > { > > if > > ($_mod['base']['output']['strict'] and ob_get_length() > 0) > > { > > ::error::go('Output generated in file > > "' . $file . '".') ; > > } > > > > ob_end_clean() ; > > } > > > > if ($obLevel !== ob_get_level()) > > { > > ::error::go('Output buffering level mismatch after > > inclusion of file > > "' . $file . '".') ; > > } > > > > return $return ; > > } > > > > This function will not be called using input data. > > I have been watching type hinting for a while now and one thing I > don't understand: hows my object of class lets say FileName that > implements __toString() is wrong parameter for your requireFile()? No problem. My patch does not have the functionality to detect the __toString method, but this could be implemented in the future. > Why should I every time calling a function cast variables manually when it > can be perfectly done by PHP automatically? Well type hinting should be used in places where casting is not necessary. You won't have to cast variables unless you specifically make them of the wrong data type, for example $number = "5", or if using form input.

« previous php.internals (#34568) next »