Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75430 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85806 invoked from network); 13 Jul 2014 16:36:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2014 16:36:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:49376] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/1E-16748-F85B2C35 for ; Sun, 13 Jul 2014 12:36:32 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 58FC18800E4; Sun, 13 Jul 2014 12:36:29 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9pnkLFNsB_tf; Sun, 13 Jul 2014 12:36:29 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 255D78800D5; Sun, 13 Jul 2014 12:36:27 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <53C2B3FF.70807@gmail.com> Date: Sun, 13 Jul 2014 17:36:24 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <82CD01FE-4DCE-4AA5-B629-B31D2C63149C@ajf.me> References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <027E65EF-C4FC-474C-92BB-D99EFADDEEED@ajf.me> <53C29EE4.3090808@gmail.com> <53C2A2F7.1000806@gmail.com> <53C2A753.2060001@gmail.com> <53C2AAF7.3060504@gmail.com> <53C2B3FF.70807@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: ajf@ajf.me (Andrea Faulds) On 13 Jul 2014, at 17:29, Rowan Collins wrote: > It's an interesting thought, but we currently have the object keyword = for that particular use case. In some languages, having a base object is = useful because functionality can be defined there, but PHP provides no = way of altering existing classes, limiting that use too. There=92s no such type hint though: $ php -r 'function foo(object $x) {} foo(new StdClass);=92 PHP Catchable fatal error: Argument 1 passed to foo() must be an = instance of object, instance of stdClass given, called in Command line = code on line 1 and defined in Command line code on line 1 Perhaps one should be added? Not in this RFC though, obviously. > Personally, I'm too much of a fan of PHP's arrays to bother with = stdClass at all; if you want to future-proof things, it's not that hard = to write placeholders ready for later implementation. I=92m thinking more about dealing with JSON and such which give you an = object. Perhaps you might have a FooBar->fromObject() method that can be = passed another FooBar to clone it, or an object decoded from JSON. = Though in that particular case there=92s no real need for a type hint. -- Andrea Faulds http://ajf.me/