Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49315 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43421 invoked from network); 11 Aug 2010 06:23:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2010 06:23:19 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.113 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.113 smtp113.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.113] ([67.192.241.113:45056] helo=smtp113.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/39-20356-5D1426C4 for ; Wed, 11 Aug 2010 02:23:19 -0400 Received: from relay21.relay.dfw.mlsrvr.com (localhost [127.0.0.1]) by relay21.relay.dfw.mlsrvr.com (SMTP Server) with ESMTP id D56AC2E4027B; Wed, 11 Aug 2010 02:23:14 -0400 (EDT) Received: by relay21.relay.dfw.mlsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 86E582E401E3; Wed, 11 Aug 2010 02:23:14 -0400 (EDT) Message-ID: <4C6241D1.6030909@sugarcrm.com> Date: Tue, 10 Aug 2010 23:23:13 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 MIME-Version: 1.0 To: Josh Davis CC: Internals References: <1281478269.6608.292.camel@guybrush> <4C61E5CA.5070604@sugarcrm.com> <4C61F3EF.5030409@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Strict typing From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > I'm sorry but I have no idea what you're talking about there =\ PHP > has a bunch of different types, the current type hinting (typechecking "int" is a different kind of type from Zend_Controller_Factory and SimpleXML - the same kind of types are "int" and "object". The former are engine types (IS_INTEGER, IS_OBJECT), the latter are classes. > I very much can, it's just not my intention. I want to be able to use > type hinting/type checking as a sanity check. If I write a method > whose signature is foo(int $n) I signal my intention to only accept Then you should use statically typed language. There's no law saying every code on the planet should be written in PHP, and PHP is not a statically typed language. So by bolting static typing onto it you are using wrong tool for the job. > If PHP was meant to prevent programmers from controlling the type of > their variables then I'm afraid there's been a misunderstanding and PHP and dynamic languages in general are not preventing people from knowing the types of variables, they however remove a number of annoyances that come with static types. You want to bring all those back - and that without the benefits that are compensating for those annoyances in compiled languages - meaning being sure upfront that the code always gets proper data in proper places. You don't know that unless you statically type and compile your whole code - so you just traded flexibility and API agility for nothing. > I'm not sure what you meant by "objects of classes can not [be > converted into another type]". Arrays can be cast as booleans (false There are no generic rules that allow conversion between two classes - such as SimpleXML and Exception, for example. In general, conversions between classes don't happen in the engine. Conversion between IS_* types happen all the time. > TL;DR: I always thought PHP would help me control the type of my > variables instead of forcing my userland code to mirror PHP's internal > functions. If you want strict typing ("control the type of my variables") I'm afraid you're using not only wrong language but wrong paradigm. You should be using statically typed language. Try C# or Java or Scala or something like that. Just having parameter typing won't help you - you'd just kick the problem around the code, it will be now it variables upstream, etc. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227