Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52008 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46300 invoked from network); 25 Apr 2011 12:24:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Apr 2011 12:24:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=martinscotta@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=martinscotta@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: martinscotta@gmail.com X-Host-Fingerprint: 209.85.210.170 mail-iy0-f170.google.com Received: from [209.85.210.170] ([209.85.210.170:54549] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/A0-40703-81865BD4 for ; Mon, 25 Apr 2011 08:24:56 -0400 Received: by iyb12 with SMTP id 12so2300188iyb.29 for ; Mon, 25 Apr 2011 05:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=r3Vuw+FU9dZoyd8KaOYpKGpwVB7UiutLZOmiA+GozCA=; b=d10rAKJ8MmtUgNvRLxZy4/AE43m7pbSOKc2weWD8iEh1GlNR1Rsym9vtw054Am8X7C nKTblE2ZqKJaAo5MQZdEWNF5hz0PCQdewEbK1vtPhoP/kFS1SD//9oZQzs01FVbwiJZ/ N7JAoH7Zg6w54BxxqFuk9hX7NwX/ZTXpkCgrg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=vwtDqZTj/i6BtRbeIrggHCtQH71/UWO4rlJouX/zJinD1hqA6yy+ljm6PZIe3yOX6s 5fwGa/dPSzTXZXLbdHm7bIaiHoKD2eXzw1sJKNWYuIfE8H0tAuZthFDxbevYx0Guqqak MnWVlIun+bvdkU6W3jRLoJ8WNv3d93Dp4CuKs= MIME-Version: 1.0 Received: by 10.231.194.165 with SMTP id dy37mr2960858ibb.30.1303734293697; Mon, 25 Apr 2011 05:24:53 -0700 (PDT) Received: by 10.231.15.141 with HTTP; Mon, 25 Apr 2011 05:24:53 -0700 (PDT) In-Reply-To: References: <5870D50E38AE4374833F83A59ABFB59E@gmail.com> <4DB4847B.3080004@gmail.com> <20110424202353.GC21102@crousti> Date: Mon, 25 Apr 2011 09:24:53 -0300 Message-ID: To: Alessandro Nadalin Cc: PHP internals list Content-Type: multipart/alternative; boundary=00504502ecce7513ff04a1bd4bdb Subject: Re: [PHP-DEV] Call non-static method staticly raise E_STRICT, but why call a static method instancely won't From: martinscotta@gmail.com (Martin Scotta) --00504502ecce7513ff04a1bd4bdb Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Martin Scotta On Mon, Apr 25, 2011 at 4:52 AM, Alessandro Nadalin < alessandro.nadalin@gmail.com> wrote: > 2011/4/24 Etienne Kneuss : > > Hi, > > > > On Apr 24 22:13:47, =C1ngel Gonz=E1lez wrote: > >> reeze wrote: > >> > Hi, > >> > I am not sure it's the right place to discuss this. someday I found = I > call a static method _instancely_. > >> > the method is just a helper method when reviewing my code. I know I = do > the wrong thing, but PHP doesn't > >> > complain about it. then I do some tests like below: > >> > >> A few corrections to your test case so it actually works. > >> > >> > error_reporting(E_ALL ^ E_STRICT); > >> I think you want E_ALL | E_STRICT > >> > >> > class A { > >> > public function static staticFunc() { > >> This is a parse error. static should be placed before function. > >> > >> > echo "static"; > >> > } > >> > public function instanceFunc() { > >> > echo "instace"; > >> > } > >> > } > >> > > >> > A::instanceFunct(); // Strict Standards: Non-static method > A::instanceFunc() ... > >> And this should be A::instanceFunc(); > >> > >> > $a =3D new A(); > >> > $a->staticFunc(); // Just static no E_STRICT error raised > >> > > >> > I know it's the wrong way to do like these, maybe there are some > historical reasons to allow these. > >> > I just wonder why previous method call raise E_STRICT but later not. > > Hi Etienne, > > > > > Nothing wrong with it. > > > > The E_STRICT is raised because when you call a non-static method > > statically, $this will not be defined and that could be a problem (e.g. > > the method could rely on it). When you call a static method with ->, it > > remains a static call, $this will not be defined anyway, and there is > > absolutely no problem with it. > > I can see your point, but I think we should drop this "feature" not to > let developers have N ways of doing the same things: if you declare a > method as static, you should be able to only call it with a static > call, not hrough an object. > > PHP usually lets you do the same thing in a few ways, and that's a bit > frustrating, because we should force some kind of best practices for > the language: not .advise, but *force*. > > My 2 cents, > Back in PHP4 it was the only way to "simulate" an static call, but nowadays it really don't make sense at all. class Foo { static function toString(Bar $bar) { return 'Foo::toString($bar)'; } function toString() { return '$this->toString()'; } } $foo =3D new Foo(); echo $foo->toString(); // instance echo Foo::toString(); // class PHP will complain about the 2nd method (can't redefine function) but for me are 2 completely different methods. I belive the current Object Model could be improved. isn't? > > > > > > Best, > > > >> > > >> > Yes, something could be done doesn't means we should, but we could > stop things like happened. > >> > >> I think it may be related to inheritance. > >> > >> > >> > >> -- > >> 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 > > > > > > > > -- > Nadalin Alessandro > www.odino.org > www.twitter.com/_odino_ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --00504502ecce7513ff04a1bd4bdb--