Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94744 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22894 invoked from network); 29 Jul 2016 14:04:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2016 14:04:02 -0000 Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.49 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 209.85.218.49 mail-oi0-f49.google.com Received: from [209.85.218.49] ([209.85.218.49:34968] helo=mail-oi0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 01/00-22810-0526B975 for ; Fri, 29 Jul 2016 10:04:01 -0400 Received: by mail-oi0-f49.google.com with SMTP id l72so107495790oig.2 for ; Fri, 29 Jul 2016 07:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=mAWxluIkK1tOXvFxRN0ByOj06FSKkz4ZJNUode3losU=; b=K0QR6mcb7xj6UpQZSRoE5xLZBQfQ7eB4FR0mH5OtVyOC8FuuUAouGcmSNAE+Q3Bpjq PefjSU40yU+dr7UxffkGZidfD5AeNmC8OS70d8eE8ij4kZSzTk6rGhu+4dIlPVfKOg+p M2kIvqOqrdYu0XXjzAgPAu1MWTNaGvoc7bH91t8cnKm0uRNUpcztu4ZqSGlR2LmX9PqB CSByy3gTu+4KIG3wnVJpJlt5s09rgO9O/fFaQMDoCX/63An72l5JPdLrpOBznNy8XjwJ gPOlRqyaWPH2DmcHVeUS2+q1KiGK5G+xbiFQEewK+ZC2Wt+gEFB5iRjC0aaZ+b0AJDCK EPwQ== 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:from:date :message-id:subject:to:cc; bh=mAWxluIkK1tOXvFxRN0ByOj06FSKkz4ZJNUode3losU=; b=DfwTqEeGB7DfpKVz0vwqVF+rSmy2xgm+yLPavkVrEIeJgpkBHExIGQlEGwU8bA4JIN k9YaVUXDah6gOGpcx6tQy5YI9xu8/UDseAivupTRhzz7fGJ3AKaT0BXAeAHcL5nHplyu y/67f9ELHB01ZpiqdqIbzYL3L//hz52w+S+xgzt+gbG8ZlHZuwl4WEVrB/M/aaW0RGcM 6fkPNhbKH2VfTUDckoT+6SH1veGZ3RmIJ1qoG9Z1mz10AoTrSghTQVlh8VlJQoTVmmLM 0pJ4U35R2zYA6mxxwrXZvLS3fzj8fb0emtvKMjnYlYx9LA2s/X8os78nqLl59AdTdgpV /3UQ== X-Gm-Message-State: AEkoouulULl5v6ZQTZzBWeISLmm0ILrl81iExxAaavx0GHcKS938gh/1gS/pzLedGtkhpnSZLXOBFdxEgiifQQ== X-Received: by 10.202.104.4 with SMTP id d4mr25904032oic.199.1469801038286; Fri, 29 Jul 2016 07:03:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.61.36 with HTTP; Fri, 29 Jul 2016 07:03:57 -0700 (PDT) In-Reply-To: References: Date: Fri, 29 Jul 2016 08:03:57 -0600 Message-ID: To: Timothy Younger Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1140e81ac728180538c6b8f8 Subject: Re: [PHP-DEV] optionally return class name from gettype From: derokorian@gmail.com (Ryan Pallas) --001a1140e81ac728180538c6b8f8 Content-Type: text/plain; charset=UTF-8 I love this idea (as I've written much the same code before), I do think it will require a full RFC though. On Fri, Jul 29, 2016 at 7:53 AM, Timothy Younger wrote: > hi Internals Team, > > i find myself writing this line frequently in projects: > > is_object($value) ? get_class($value) : gettype($value); > > it seems i'm not the only one: > > > https://github.com/search?l=php&q=get_class+gettype&ref=searchresults&type=Code&utf8=%E2%9C%93 > > although it is small, it amounts to a lot of duplicated logic in need of > testing. i'm looking to write that line, and its tests, one last time. > > i think it's a bit trivial to warrant a standalone lib, but might already > exist or fit in some helper package. > > instead, what do you think about an optional param for the gettype method > to provide this functionality? here's the new (hopefully > backwards-compatible) behavior: > > var_dump(gettype(new \stdClass(), true)); > string(8) "stdClass" > > var_dump(gettype(new \stdClass())); > string(6) "object" > > here's my commit, proposed for php/php-src: > > > https://github.com/abacaphiliac/php-src/commit/f4e2fae9145cec5af94f197acf71dae02cd61b08 > > and my commit's build on travis: > > https://travis-ci.org/abacaphiliac/php-src/builds/148218512 > > any interest? if gettype isn't the right home for this logic, then perhaps > someplace else? > > thank you. > Tim Younger > --001a1140e81ac728180538c6b8f8--