Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91002 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68671 invoked from network); 28 Jan 2016 22:35:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2016 22:35:58 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.160.178 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.160.178 mail-yk0-f178.google.com Received: from [209.85.160.178] ([209.85.160.178:33422] helo=mail-yk0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/81-53831-DC79AA65 for ; Thu, 28 Jan 2016 17:35:57 -0500 Received: by mail-yk0-f178.google.com with SMTP id k129so49305155yke.0 for ; Thu, 28 Jan 2016 14:35:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ISgLMw02/CdH/cdFZjHRwUzoVtf1sPaBjTiACXj7wPc=; b=DnRY0ZMYVLnZlmaRkDfS4jtVF5dVAE99OKC9l7ezK6COmAQvUdUr6QLpOBp7XYzbq7 /wk+WG0eI08Yn09fkJCAsEYA9mBK/47aDKA51vG70M92RwOKrnuAa9FNkjCxmGsnBqzT 8rSsSuDeyqjVHOzAblwyeCfcRPh12+P+GJzafDTpfw/ATpDTXBLdAfh5xbzSd3z4sLLf b2Ysvql0GCN0QzFs/g7ZU7MAxZcwFNccTH9ga1DDsFG+wwlllWtibPCiHMOAALAaFvhF wnjdrYG3itXqErqUIBePM2b8LtVsixEBD1PxOVaG0txhEtBc7pb5J8NvTTv3JR04wHZe 8rlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ISgLMw02/CdH/cdFZjHRwUzoVtf1sPaBjTiACXj7wPc=; b=jfVPmDooYfQzi6u5JL/wHRiuSK2K9JuBg/7jcHUU+fooYijFeMGfFXbk0QlrVSYO04 N7oSPffH2/ZH97kN9TrJLnQx331WmKIo3WLsKHy7SeZaihC7u/4ukXc4bQdk9RLriQ2E EGDwpKYliGHM6a/4pDgjxIFYUztAOQZkfrUbAVF7GOUjX6RGMhk61QnY1N/adPQj0mkJ eMfbYAqRzSIo2ASxW+IMMkEyCV/WXxVsB977YkrvGOf2jkNzda86bTtomq7vcsoPSsE3 pSgesNVW4IqS9OXP8owtM/6IKWaH1Cn/yLRaDuUH2ruzeG6MEvKbDceUoWc7c+QUUxGG 9f2Q== X-Gm-Message-State: AG10YORERsjd0NY7hzMbXs0jXtf1KwN78X4gWKomZ4ZSXXrZJMRDPm0eRHiTxrmjNgZoQwW2XB0vew1Hxe3a4A== MIME-Version: 1.0 X-Received: by 10.13.192.5 with SMTP id b5mr2923068ywd.114.1454020554393; Thu, 28 Jan 2016 14:35:54 -0800 (PST) Received: by 10.37.83.131 with HTTP; Thu, 28 Jan 2016 14:35:54 -0800 (PST) X-Originating-IP: [78.145.240.77] In-Reply-To: References: Date: Thu, 28 Jan 2016 22:35:54 +0000 Message-ID: To: Lorenzo Fontana Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] get_class behavior From: danack@basereality.com (Dan Ackroyd) On 28 January 2016 at 19:17, Lorenzo Fontana wrote: > Hello everybody! Hello Lorenzo, > If *$result* is *null* the output of *get_class* is the name of the > containing class instead of the name of the object I wanted. Yes, that is bad. Perhaps a smaller change would give you the desired behaviour though? If we just give a warning/error if any non-object type is passed as the parameter, that would achieve what you want wouldn't it? And it provides a slightly easier 'upgrade' path for people who, for whatever reason, are currently passing null to it. > the name of the containing class can be easily obtained via *__CLASS__ > or via get_class($this)* or via *get_called_class() The first two can't be used directly as a callable, and so can't be passed around as a function. And get_called_class() returns the late static binding class. So if the smaller change of just giving a warning/error on any non-object as a parameter gives the desired result, I would recommend doing just that. It might even be possible to do it as a bug fix... cheers Dan ## Refactoring if non-objects are no longer allowed. Current code: echo get_class($result); Would need to be changed to: if ($result === null) { echo get_class(); } else { echo get_class($result); } ## get_called_class is late static binding. class foo { static function bar() { //return $fn(null); echo get_class()."\n"; echo get_called_class()."\n"; } } class Quux extends foo { } Quux::bar(); // Output is: // foo // Quux ## Callables can passed around class foo { public static function bar(callable $fn) { return $fn(); } } echo foo::bar('get_class');