Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94743 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21351 invoked from network); 29 Jul 2016 14:00:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2016 14:00:07 -0000 Received: from [127.0.0.1] ([127.0.0.1:10320]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 83/70-17523-6616B975 for ; Fri, 29 Jul 2016 10:00:07 -0400 Authentication-Results: pb1.pair.com smtp.mail=abacaphiliac@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=abacaphiliac@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.49 as permitted sender) X-PHP-List-Original-Sender: abacaphiliac@gmail.com X-Host-Fingerprint: 209.85.214.49 mail-it0-f49.google.com Received: from [209.85.214.49] ([209.85.214.49:34624] helo=mail-it0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/40-17523-8FF5B975 for ; Fri, 29 Jul 2016 09:54:00 -0400 Received: by mail-it0-f49.google.com with SMTP id j8so30701252itb.1 for ; Fri, 29 Jul 2016 06:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=mGaSFRebN03W5wRFsfTdvmSNkX8VPk6AQDA9gto0xyA=; b=E3ixmsC6eJoIahuvaxPJR1/J/ePwKST7Q0kK8JZAnR8xqs3A+E97eyRbsALG93NA47 j7nwZmilQ60RAXENvDq52SPCjw4hjL4v9ymz3h3EJK4VWNOmSUhGce5IX87Rs12wwTWe bvKvtzMiIQGnJpljYkEOHRepUogXVBUIEw64ynijymtUkqKilNobusO8ZhuhuwEXAb8F 4OehL6qtZNgyc6FDxCVCd2cYV7uhGYmb977QmF0m3aJGxNXPy2xe16KX5VfMh7Apq9fE aUiIUq1hZVXVrgUZqw5lHc5MZjju6avfJ15P9huu/1WpiuOyji/4Zz+537ybae3SpZ7X 2Vww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=mGaSFRebN03W5wRFsfTdvmSNkX8VPk6AQDA9gto0xyA=; b=eEoybdLJkhqhPb7Z8tuUmOo8ya5MECyDilroAxO3yf1xlNB3LpwMaSCzRlZZCscxMw kN6zCP1d6pjmvLvA3M6OhqqQJjF06G1tzvGFWR1vNa3Um4Zp5xpLdUs2aXyi1y/R/4/o X5+zhTWVRr1BluSFNmUZAwzQMTvfKIHkv25Kzi7HeMz3HJQ4KTwtARStQQ5OGGKvDaUK 8D60uDlI3bHQYZ+0VSmMaRHQpibuHdpAzoCyRhSjNuAsAmo8EXMmpQmiZHll52KARks0 JtbhXF9ZF2X3ii31tBStqg2TZo6hJVXmIh2VHiWf8srMF8aIzJFhQFYSFgIKufH19EBC +lHQ== X-Gm-Message-State: AEkoouvu8DmM9YY3n811iKy+Ssq/0oMFa0vJfTkSU2/aEmGjyx2VbpUsW5m8madgoBeJ3+UjNs92Gva3yrJg/w== X-Received: by 10.36.90.79 with SMTP id v76mr42953743ita.16.1469800437601; Fri, 29 Jul 2016 06:53:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.107.75 with HTTP; Fri, 29 Jul 2016 06:53:57 -0700 (PDT) Date: Fri, 29 Jul 2016 06:53:57 -0700 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a1143d25ef95aec0538c6945f Subject: optionally return class name from gettype From: abacaphiliac@gmail.com (Timothy Younger) --001a1143d25ef95aec0538c6945f Content-Type: text/plain; charset=UTF-8 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 --001a1143d25ef95aec0538c6945f--