Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92958 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5138 invoked from network); 29 Apr 2016 19:10:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2016 19:10:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.170 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.170 mail-pf0-f170.google.com Received: from [209.85.192.170] ([209.85.192.170:34289] helo=mail-pf0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/D3-26386-EB1B3275 for ; Fri, 29 Apr 2016 15:10:54 -0400 Received: by mail-pf0-f170.google.com with SMTP id y69so51697600pfb.1 for ; Fri, 29 Apr 2016 12:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=Ucaivi4vntdI73ZFgvg2b0jcx/7l1csbvgARHZAPnys=; b=hegOvGbg016+juInEw+qvxCapDZJoOh0ztztYPf7Y0fh1zJ45GaMjiw5dGcgNhx40c DHaPHEEyiGSWXgSVazekvpmZAU2ifG5fSnTJM4CTY9V8cvVYswy2MMsd651wU0gy/i7S fix17DjjzFeERlvKkOWXIcEH6+L6vKR+W/xCCkm7hy0Knu0ffx0JSpEyd2WQyTRmf1hq UU3Ffw+BzC4Q1HGxJjRunFGnQe6hh0BOSU3WWAP5LQZOPclnt2aw/cH69sHCkl8hZhy6 XCK+vsCKRxQhSlZtfr6fKHr0l/FjerxfPLfQEKgjmuBRqwqn182L5drPA5SA7BocyNw2 nhZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=Ucaivi4vntdI73ZFgvg2b0jcx/7l1csbvgARHZAPnys=; b=hh2RIL/+lQtyGIJd+fd9YmGppxovcZUpwDscabFhRuMKWzgeFRuYaSrxTMotZyIGy1 eRQayXbNJw/ue6LkOQ0dhMFDjEIbWXJB55nonGnwzNLCOXTiGNK+nRthC+Jw3P+EaiGA +XMBgOeqlzXJmmDZZoKNJ8FaZx6H++dQcTg4Lak1Xe9zmZgGzMMleJ5aH0memZc2F1/b mJWs6n+MzC04QnW058UX2UC2PwLXgac27qsfOsnZNY04YFqIuKlk13TM8G0tmrN/zZsL ihIRKzOxrhNJ3TZ3fquh/s4P8dYKejkoz/eGyt4eF3UtjTNiEbBfN0o4BNGfAgBNqYgb jr3g== X-Gm-Message-State: AOPr4FW2Zdjj98FwJsuQP334S43ON5/MDv4oAEitHmWiHumdB0qag2Pz5nZxyfvAS1MeVw== X-Received: by 10.98.109.198 with SMTP id i189mr31228750pfc.106.1461957051661; Fri, 29 Apr 2016 12:10:51 -0700 (PDT) Received: from Stas-Air.local (76-220-46-95.lightspeed.sntcca.sbcglobal.net. [76.220.46.95]) by smtp.gmail.com with ESMTPSA id a5sm25606189pat.19.2016.04.29.12.10.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Apr 2016 12:10:50 -0700 (PDT) To: Nikita Popov , PHP internals References: Message-ID: <3de7a02a-0d76-cd48-6001-b1b9456c2690@gmail.com> Date: Fri, 29 Apr 2016 12:10:48 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Forbid $this being null in instance methods From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > I'd like to submit a small RFC for your consideration, which ensures > something that really ought to be a given already: If you use $this in an > instance method, you should actually get a $this (and not NULL). > > https://wiki.php.net/rfc/forbid_null_this_in_methods > > As this is targeting PHP 7.1, the RFC is careful to retain compatibility > with certain legacy PHP 4 code patterns. Unfortunately, this does not exactly preserve compatibility. Consider: public function legacyMethod() { if(is_null($this)) { trigger_error(E_DEPRECATED, "legacyMethod() should be called with an object now!"); return self::getDefaultInstance()->legacyMethod(); } print "I am an ugly legacy method!"; $this->doSomeStuff(); return true; } Unfortunately, I've seen this pattern not once when dealing with APIs which were grown from PHP 4 code and must maintain BC - e.g. have code relying on legacyMethod() both being called statically and called on an object and legacyMethod() being overridden by extending classes. It is an ugly code and an ugly situation to be in, but it is a real pattern that happens. Despite the RFC claiming HHVM does not support this pattern, it does: https://3v4l.org/1QrY7 Unlike PHP, it doesn't even throw deprecated error in that case. Given that this RFC does not seem to enable anyone to do anything additional that couldn't be done before, just removes the features from language, I see any advantage in doing it so far. I also do not think enabling using $this as a regular variable is a particularly good idea. It does not add anything - there's no real need to name your variables specifically "$this", you can choose any other name - but it creates potential both for confusion and for weird errors when you refactor stuff. Again, don't see any real advantage in this. -- Stas Malyshev smalyshev@gmail.com