Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52004 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20142 invoked from network); 25 Apr 2011 07:52:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Apr 2011 07:52:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=alessandro.nadalin@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=alessandro.nadalin@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: alessandro.nadalin@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:35483] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/6B-22678-15825BD4 for ; Mon, 25 Apr 2011 03:52:49 -0400 Received: by qyk32 with SMTP id 32so658123qyk.8 for ; Mon, 25 Apr 2011 00:52:46 -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:content-type:content-transfer-encoding; bh=GhcS2rQE6H6SUSOGQwoSehBKlZikAk5ECoHVCd1f8lA=; b=MWs+Lr2ovSZwGjhWtvEjgToUc27Wsaqt03v+qNZImQqZwBB5MXwo1Jle9rV4L92jpj X7c+SbThG5hQHG35EwJzR8MWogl654Uy9aPoqJMf/fuIf/Cs2VcnkgXUJWzVS3f7qyas fip4iiRClQXoH9wv15450hF0p9oxuRO4FapaU= 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 :content-type:content-transfer-encoding; b=ctnUP/U9CFjD/PyZBIk6DnxdaEUQMY1Hxi7WuWOVPnW87yajZne5IWw3ITPLIStzfg LGckLywBC+lhz35Kt2ZAMlAC+VNVwi76YTKzpHOcCfayTTAcJANhjkRg5sic7hAAfepy d/6WA5QQL2dwkyj5nru30L6Zp60XY4HhczUX0= MIME-Version: 1.0 Received: by 10.229.17.17 with SMTP id q17mr2537632qca.154.1303717966459; Mon, 25 Apr 2011 00:52:46 -0700 (PDT) Received: by 10.229.241.209 with HTTP; Mon, 25 Apr 2011 00:52:46 -0700 (PDT) In-Reply-To: <20110424202353.GC21102@crousti> References: <5870D50E38AE4374833F83A59ABFB59E@gmail.com> <4DB4847B.3080004@gmail.com> <20110424202353.GC21102@crousti> Date: Mon, 25 Apr 2011 09:52:46 +0200 Message-ID: To: PHP internals list Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Call non-static method staticly raise E_STRICT, but why call a static method instancely won't From: alessandro.nadalin@gmail.com (Alessandro Nadalin) 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::instance= Func() ... >> 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 histo= rical 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, > > > Best, > >> > >> > Yes, something could be done doesn't means we should, but we could sto= p 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 > > --=20 Nadalin Alessandro www.odino.org www.twitter.com/_odino_