Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46648 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94489 invoked from network); 12 Jan 2010 01:29:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2010 01:29:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.227 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.220.227 mail-fx0-f227.google.com Received: from [209.85.220.227] ([209.85.220.227:42342] helo=mail-fx0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B0/33-26332-770DB4B4 for ; Mon, 11 Jan 2010 20:29:28 -0500 Received: by fxm27 with SMTP id 27so7415031fxm.23 for ; Mon, 11 Jan 2010 17:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=kz3o7hW33zAicxT5EE7W3iRUeAEvn++U3gP1fNcVKk0=; b=x+yj0BgJ4oYov1lBWwXAkc5rsfuCv7PpdA2QvogXLRz2BTRKLCRsWat6wLWDc0C+oO F8rdu10Tf1VsQdHPShekPjnJpZQdXKfhLSpCWSdDZxG4RzwCZZc58cyp4WVpIoXQ7iBA BErMT+yhcxG1899XJGe/L4zdTnXoydf99/Now= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=XJBHxQp32wJyOVmVr1S/AFHDPruQ4qNDannDpuDf0jeoVMgVBS6mt64To5SYnwZ/bw X7nmWMEIO4cCDGIvfD82ZzRGt5U38Qd58/FLaxJaQX/7AgmPot4PpA5gcnKft/wR6m0x PP4LMIOVq6D4x9KjwELHIpLVdoHpdxqm4I9xM= MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.87.74.14 with SMTP id b14mr8438761fgl.65.1263259764809; Mon, 11 Jan 2010 17:29:24 -0800 (PST) In-Reply-To: References: Date: Tue, 12 Jan 2010 02:29:24 +0100 X-Google-Sender-Auth: e30fe2ef5f4a8c70 Message-ID: To: Clint Priest Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] __toString(), __toArray() From: colder@php.net (Etienne Kneuss) Hello, On Mon, Jan 11, 2010 at 7:31 PM, Clint Priest wrote: > I know there's been requests to add a __toArray() and most of the argumen= ts > against it is that there are too many magic functions already. =A0I just > thought I'd propose an alternative that would satisfy all of them. > > Why not a __cast($Type) magic function? I'd advance two reasons against this idea: 1) It's more self-explanatory to explicitly call the appropriate converting method, enough with implicit madness! 2) For some operations, you'd have to know the types in advance before knowing what operations needs to be performed: $obj1 + 2; Now what __cast should be called? Int? Float? Also, what about $obj1 + $obj2: Int? Float? Array? Another example: str_replace($obj1, "bar", "foo"); what to call? __toString or __toArray? str_replace accepts both. IMHO it would only make sense to invoke methods on explicit casts only, otherwise it will just be a mess with PHP's current type juggling. But, as we seen with __toString, limiting the field of application was annoying (and it was later extended to nearly all string usages). So, what will it be? Inconsistent and Confusing or Limited and Annoying? > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Etienne Kneuss http://www.colder.ch