Re: Scalar type hinting

From: Date: Mon, 27 Feb 2012 16:19:17 +0000
Subject: Re: Scalar type hinting
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-58148@lists.php.net to get a copy of this message
On Mon, February 27, 2012 8:29 am, Michael Morris wrote: > Both of these must be > declared formally (otherwise PHP assumes scalar) I believe you mean "dynamic" or "loose" datatyping. Scalar would imply that you couldn't do this: array $a = array(); //force $a to always be array, and never anything else object $o = new Object(); //ditto, only object > // A tolerant variable. > integer $a = 3; > > // A strict variable > strict integer $b = 2; > > Tolerant variables silently cast values to their declared datatype. > Maybe they should raise E_NOTICE? Raising E_NOTICE is a backwards compatible "break" of little added value. Programmers who want their variables strongly typed will use strict, those who don't won't. A proposal that includes an explicit "loose" or "dynamic", which means the default behavior, but is self-documenting as intentional loose-ness would be a better idea, imho. The idea is sound, though I daresay the actual implementation may be problematic to the point of "impossible". PRESUMPTION: *ANY* strict datatype could also be NULL, to represent a failure condition... Otherwise, when you are out of RAM: strict $o = new Object(); //violates strict, because Object HAS to be NULL, as there is no RAM left for it to be an object. -- brain cancer update: http://richardlynch.blogspot.com/search/label/brain%20tumor Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE

« previous php.internals (#58148) next »