Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46677 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4019 invoked from network); 13 Jan 2010 10:22:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jan 2010 10:22:57 -0000 Authentication-Results: pb1.pair.com header.from=ionut.g.stan@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ionut.g.stan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.213 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ionut.g.stan@gmail.com X-Host-Fingerprint: 209.85.218.213 mail-bw0-f213.google.com Received: from [209.85.218.213] ([209.85.218.213:57190] helo=mail-bw0-f213.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/26-00773-00F9D4B4 for ; Wed, 13 Jan 2010 05:22:57 -0500 Received: by bwz5 with SMTP id 5so15000212bwz.23 for ; Wed, 13 Jan 2010 02:22:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=IDrrgLKsl4ETtLMw1KN4+BXgw0THYEylXl3gHfF3uVA=; b=AGX65jkZtTUAypiyfdfrci0hBe65KF8h4U3Ikoh7DAD21AW5xZ11+v4R/1ofheTMNC NTfBdnSK131Gy6tC9ALrafPg8Jb7YW4b2FtzrEP2e2qZyPdaIs85ZIlyY05xV3uoqGGT Kcn2IpIXvVz713kZn1glCw+vxhOu9P9D0dzO0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=h3hKrUe6oFmX++npIVUcmC64u9zBMGpLwTurMst5jHUeZjKJ4bi2xFcKNptGrOavff 84+61waUxnjrtQwiGwSPAAN/k4jSCy9W1P3RC7lBpGjs78DQat/7ZROD+QP7V38sBMJj olNuokbXi6ZV/eQKbpqyDEg17kl/sTeP6tq/o= Received: by 10.204.49.85 with SMTP id u21mr1363059bkf.148.1263378173248; Wed, 13 Jan 2010 02:22:53 -0800 (PST) Received: from ?192.168.10.112? ([82.208.177.66]) by mx.google.com with ESMTPS id 13sm3509007bwz.6.2010.01.13.02.22.50 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 13 Jan 2010 02:22:50 -0800 (PST) Message-ID: <4B4D9EEB.9050306@gmail.com> Date: Wed, 13 Jan 2010 12:22:35 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: internals@lists.php.net CC: 0xcafefeed@gmail.com References: <3A.94.26332.3E9EB4B4@pb1.pair.com> <68de37341001121810x10be424fu842402a398d3709e@mail.gmail.com> <68de37341001121829p3a2f6a62y6eb2a45863e62ae6@mail.gmail.com> <4B4D371D.3010200@warpmail.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] __toString(), __toArray() From: ionut.g.stan@gmail.com ("Ionut G. Stan") It appears that, mm w is talking about some aspect oriented feature. I would welcome a magic method that would intercept calls/access to existing methods/properties (not only inaccessible ones), in the same sense that __getattribute__ works in Python for example IIRC. It may also be a good time to unify properties and types in PHP (we see a lot of problems with lambdas assigned to object properties). But... that's certainly another topic. On 1/13/2010 6:09 AM, mm w wrote: > I don't move any magics,I am worried about your knowledge of php, > there's people to give you money ? weird, set get call are only call > when something doesn't exist catch or catch-able concept is to be able > to catch any existing calls no the dynamic ones. > > > On Tue, Jan 12, 2010 at 6:59 PM, Clint Priest wrote: >> >> >> Eddie Drapkin wrote: >>> >>> What you're proposing is just forcing __call, _callStatic, __get and >>> __set into a single method, which does nothing to reduce the amount of >>> magic, only obfuscate it. And it certainly offers no alternative to >>> "__cast", at least not that I can see. >> >> I agree, moving all magic to a single function doesn't help the situation at >> all, it simply complicates it. >> >> All this talk of "too many magic functions" is a little comical, its all >> trying to overcome operator overloading type functionality in other >> languages. >> >> __get()/__set() would be equivalent to getters/setters supported by the c# >> language >> >> __toString(), __toArray() would be equivalent to operator String() in c++ ( >> if I remember correctly ) >> >> I would definitely love to be able to, at the very least, cast an object to >> an array but I figured a more general purpose __cast() would be most >> beneficial to all. >> >> I think the ambiguity question for some functions accepting mixed as a >> parameter type could be solved in aforementioned ways. >> >>> On Tue, Jan 12, 2010 at 9:11 PM, mm w<0xcafefeed@gmail.com> wrote: >>>> >>>> the multiplication of magic, the pointed point, need to read more >>>> carefully >>>> >>>> On Tue, Jan 12, 2010 at 6:10 PM, Eddie Drapkin >>>> wrote: >>>>> >>>>> How does this have *anything* to do with the discussion at hand? >>>>> >>>>> On Tue, Jan 12, 2010 at 9:09 PM, mm w<0xcafefeed@gmail.com> wrote: >>>>>> >>>>>> don't worry it's only for people who are working with MVC and >>>>>> RootObject structure, there is too much magics already and __cast is >>>>>> not needed at all, >>>>>> as we cannot monkey patch to add an observer on itself, a nice >>>>>> solution should have a catchable object so __catch any calls >>>>>> >>>>>> function __catch($data, $type) { >>>>>> if (method == $type) { >>>>>> if (data[selector] = 'setValue'&& observedValueForKeyPath) { >>>>>> $this->_setValue(($data['arg']); >>>>>> return; >>>>>> } >>>>>> } >>>>>> continue_natural_call(); >>>>>> } >>>>>> >>>>>> we could imagine to have a root-object-built-in-class that is >>>>>> naturally observable, or a root classObject at all, anyway it's only >>>>>> something for people who are doing OO programming, >>>>>> so don't worry >>>>>> >>>>>> On Tue, Jan 12, 2010 at 2:40 PM, Chris Stockton >>>>>> wrote: >>>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> On Mon, Jan 11, 2010 at 8:32 PM, mm w<0xcafefeed@gmail.com> wrote: >>>>>>>> >>>>>>>> cast is not needed in PHP >>>>>>>> >>>>>>>> i 'd rather be more interesting in >>>>>>>> >>>>>>>> class Obj { >>>>>>>> function __catch($data, $type) { >>>>>>>> //$type [ static_method, method, get_property, >>>>>>>> set_property] >>>>>>>> if (observed&& $type == set_property&& >>>>>>>> somevalueIsObserved) { >>>>>>>> $observer->notify("somevalue::valueWillChanged"); >>>>>>>> $this->somevalue = $data['somevalue']; >>>>>>>> $observer->notify("somevalue::valueDidChanged"); >>>>>>>> } else { >>>>>>>> continue__call(); >>>>>>>> } >>>>>>>> } >>>>>>>> } >>>>>>> >>>>>>> What? ... >>>>>>> >>>>>>>>> Etienne Kneuss wrote: >>>>>>>>> This is where operator over-loading would be useful however perhaps >>>>>>>>> only >>>>>>>>> explicit casts would make sense here. >>>>>>> >>>>>>> I beleive adding a __cast(string $type) would be a useful feature for >>>>>>> me, very often I have a toArray method defined. I agree with you that >>>>>>> due to unexpected edge cases with operator precedence and general type >>>>>>> juggling that __cast should only be called on explicit (cast). >>>>>>> >>>>>>> I.E.: >>>>>>> class Int { public function __cast($type) { return 'int' == $type ? 15 >>>>>>> : 0; } } >>>>>>> $r = new Int; >>>>>>> >>>>>>> var_dump($r + 1); // 2 >>>>>>> var_dump((int) $r + 1); // 16 >>>>>>> var_dump((bool) $r + 1); // 1 >>>>>>> >>>>>> -- >>>>>> PHP Internals - PHP Runtime Development Mailing List >>>>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>>>> >>>>>> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > -- Ionut G. Stan I'm under construction | http://blog.igstan.ro/