Re: [PATCH] Optional scalar type hinting

From: Date: Sun, 18 Nov 2007 23:13:55 +0000
Subject: Re: [PATCH] Optional scalar type hinting
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-33266@lists.php.net to get a copy of this message
On Nov 18, 2007 5:52 PM, Cristian Rodriguez <judas.iscariote@gmail.com> wrote: > 2007/11/18, Derick Rethans <derick@php.net>: > > > I am actually thinking that it might be a good thing to add more and > > more. I know my quick hack isn't the best implementation though. > > Yes and it is an alternative and not a mandatory thing to use.. as long as : > > <?php > > function foo(int $num) { > return $num > > } > > foo("12345") // emit fatal error, NOT accept it as valid integer > > all is fine and Im all for it ;) > -- > http://www.kissofjudas.net/ > I was thinking at something along the lines of objects also for instance: $i = new Integer(33); function foo(Integer $var) { } foo ($i); else it emits a fatal error. But also if you do $i = "Name"; that would emit a fatal error because the value is suposed to be an int. This might look a bit too much like java, but as an extension it could be something quite interesting I believe. String, Object, Integer, Scalar, Float and what else. So thinking of something like $string = new String("Foo"); $string = "bar" or $string->setValue("Bar"); would do $float = new Float(4.242); $float->setValue('foobar'); // That emits an error $float->setValue(3.14159); echo $float; (__toString) or echo $float->getValue; to echo it's content/value and so on. Would that be "too" java-ish to be something considered in php6 ? ;-) > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- David Coallier, Founder & Software Architect, Agora Production (http://agoraproduction.com) 51.42.06.70.18

« previous php.internals (#33266) next »