Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98541 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62871 invoked from network); 15 Mar 2017 18:32:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2017 18:32:05 -0000 Authentication-Results: pb1.pair.com header.from=bburnichon@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bburnichon@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.176 as permitted sender) X-PHP-List-Original-Sender: bburnichon@gmail.com X-Host-Fingerprint: 209.85.128.176 mail-wr0-f176.google.com Received: from [209.85.128.176] ([209.85.128.176:34157] helo=mail-wr0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/80-38004-3A889C85 for ; Wed, 15 Mar 2017 13:32:04 -0500 Received: by mail-wr0-f176.google.com with SMTP id l37so16934376wrc.1 for ; Wed, 15 Mar 2017 11:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uGCTrdGi0z8MoyVgbXFH4ZpV68ogHOiRZjy4Gs/a9OU=; b=SHjDmLUlBJsHrosXQBAgIoxlPIC4nLp2DdHs6ehFOzBvcmxz+uP8Gd/YrSjjP96ynu I/aDpwWMxawdPZ3Tp1e3Kxz3nUggaBcJTOrFr7QHsc3UKsU+n+ud46Gz4x2pl+QdNdyd dW9y6oxCso1ol/qf5Ng7KQEQYgIw+8KDWYmU2JhneyESa0VhlOWtW9vNkxAimqjzsH4n aNXEleCSlaXhHFJC//1clEM+qVEZKpGUqc1cDYOsb24Zg2d55S/SNEY3rRK1Op6oL/mM +HnXY15Tbut74rF6ke8KTQVTPmxKixb1mNByJrXdccR2eBAw5lben6fNXZJKPlINVZLl CgAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uGCTrdGi0z8MoyVgbXFH4ZpV68ogHOiRZjy4Gs/a9OU=; b=Ka1x0lr7BPrQPWysAXo3Ij4KcW+qOHQATWM5rAYZTPV+HratlppQtChBTXUWE89AIH GxdQ1eyliS6HpFvWGpjDeC0HADG3MoLcT+bnyI4+bHB7sxlTk4NTbeHgCxd4qeTWnTVb 0VfuoczmCq0rozoojorrT2TXDrG6DPCvHWkP03I6jCw07SgCOU6qod4q21uiQJvTjnrt MvKjA63+niBv4WbDva0QEqo6usWqLQxdNNRYR903nwPE5jeiD8f8T0gyazuH6zagWhlC ISdqfvYx/1KhR4U1/x+SWn+lah/y52ARZHR/QFiHYz/IA95vcz1RoLcDbspJeW9OpUt/ ig6A== X-Gm-Message-State: AFeK/H0BwtJlrdll1s98VadwKqWJTv8wCJtTS8A014DULc6+bPNmCsowWZJtH8TduEU15hrqtwbTGyVUZTv1DQ== X-Received: by 10.223.134.69 with SMTP id 5mr4684051wrw.22.1489602720604; Wed, 15 Mar 2017 11:32:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 15 Mar 2017 18:31:50 +0000 Message-ID: To: Ryan Pallas Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1149244004a883054ac929b9 Subject: Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array From: bburnichon@gmail.com (=?UTF-8?Q?Beno=C3=AEt_Burnichon?=) --001a1149244004a883054ac929b9 Content-Type: text/plain; charset=UTF-8 > I like the idea kind of, but would this remove the ability to cast to > array all classes not implementing __toArray, as is the case with > __toString? This would be a HUGE BC if so: > > $ php -r 'class Foo {public $foo = "foobar";} var_dump((array) (new Foo));' > array(1) { > ["foo"]=> > string(6) "foobar" > } > $ php -r 'class Foo {public $foo = "foobar";} var_dump((string) (new > Foo));' > PHP Recoverable fatal error: Object of class Foo could not be converted > to string in Command line code on line 1 > $ php -v > PHP 7.1.2 (cli) (built: Feb 27 2017 00:02:44) ( ZTS ) > No. For me, classes not implementing __toArray() should keep current behavior. That was what I had in mind when I wrote that __toArray() should have a default standard implementation. Same restrictions could be applied to this magic method: http://us3.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring By this, I mean, no exceptions should be thrown in this method and return value MUST be an array. --001a1149244004a883054ac929b9--