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 <abacaphil...@gmail.com> 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 >