Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29223 invoked by uid 1010); 14 Jan 2005 16:04:25 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 15644 invoked from network); 14 Jan 2005 16:02:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2005 16:02:56 -0000 X-Host-Fingerprint: 200.32.3.79 200-32-3-79.prima.net.ar Linux 2.4/2.6 Received: from ([200.32.3.79:57345] helo=mail.bpservers.com.ar) by pb1.pair.com (ecelerity HEAD (r4059)) with SMTP id E1/30-44803-70DE7E14 for ; Fri, 14 Jan 2005 11:02:17 -0500 Received: (qmail 31962 invoked by uid 0); 14 Jan 2005 16:02:05 -0000 Received: from unknown (HELO ?192.168.0.240?) (168.226.115.158) by 200-32-3-79.prima.net.ar with SMTP; 14 Jan 2005 16:02:05 -0000 Reply-To: lpedretti@suserver.com Organization: Axon Sistemas To: internals@lists.php.net Date: Fri, 14 Jan 2005 13:01:43 -0300 User-Agent: KMail/1.7 References: <20050110140943.99185.qmail@web41415.mail.yahoo.com> <200501101315.32968.lpedretti@suserver.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-ID: <200501141301.43162.lpedretti@suserver.com> Subject: Re: [PHP-DEV] Basic types hinting and variable hinting From: lpedretti@suserver.com (Leonardo Pedretti) On Monday 10 January 2005 17:58, Derick Rethans wrote: > On Mon, 10 Jan 2005, Leonardo Pedretti wrote: > > Are there any plans to include type hinting with basic types and type > > hinting for variables? (such as optional declaration) > > There are no such things planned, except for "array" afaik. That is quite good already, but... > > It would be useful to declare the type of a data member of a class, for > > example, for automation of data fetching from SQL databases or such > > things. > > That is *definitely* not on the list - PHP is weakly typed and will > remain so. I can't understand why being able to point some variable as strongly typed = and=20 remaining the default as weak typed would make php strongly typed. In fact,= =20 that assumption IS incorrect, a language is weakly typed when variable type= s=20 are not forced to be respected though they already exist and change=20 dynamically, and the programmer actively having to point a variable as=20 strongly typed for the scope of a function obviously does not contradict th= at=20 postulate. Even more, just having that feature in object data members would be heaven.= =20 Basic type hinting can be emulated using is_int, is_string, and so on on th= e=20 beginning of the function needing that, but for objects it can not be done = to=20 know the type of a data member previously to it's assignment, and having to= =20 assign a value in the constructor forces one to declare a specific=20 constructor doing that for classes that derive or implement an interface th= at=20 has functions using that type for automation of tasks. Code just would be=20 really so cleaner just by allowing one to put a type in front of an object= =20 data member declaration and allowing to retrieve that type. =46or example, consider this code: abstract class base { function __construct() { // constructor just sets up some things } function someoperation() { /* this function needs to load the data members of basic types with some= =20 clear values but everything that is an object or an array must be filled=20 through some specific process that can be automated just knowing the specif= ic=20 type in advance */ } } class specific_class { function construct() { $var1 =3D new SomeClass; $var2 =3D new SomeOtherClass; } private $var1; private $var2; } would the types could be showed int the class, function someoperation could= =20 still perform its task without any change, but specific_class now would be= =20 just the following: class specific_class { private SomeClass $var1; private SomeOtherClass $var2; } Which is identical to the upper version. Moreover, specifying the construct= or=20 parameters in the declaration should not be a problem, as it is equivalent= =20 code to the upper version. Well, i hope all this can be useful! Regards Leo > > Derick > > -- > Derick Rethans > http://derickrethans.nl | http://ez.no | http://xdebug.org =2D-=20 Leonardo Pedretti Axon Sistemas L=EDder de Equipo Proyecto Basalto