Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101298 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97436 invoked from network); 11 Dec 2017 00:52:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Dec 2017 00:52:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.215.50 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.215.50 mail-lf0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:38326] helo=mail-lf0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/54-53433-3C6DD2A5 for ; Sun, 10 Dec 2017 19:52:20 -0500 Received: by mail-lf0-f50.google.com with SMTP id e137so17334020lfg.5 for ; Sun, 10 Dec 2017 16:52:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=rFILUL0jtfDsUEFL3EAT6tZ5FsaqXgMag0W+ybgD8RQ=; b=JjXw3sQw6j+Ri2H5Y3oczKELCki+Zp0mmCHJwcL9RVSfpwEXJEJpIzuMhoy+Qs1NXi vHqq76O9U8zVzfdcP0vfu4Woj/3wbbuVXbcE02ahNgBTfVRShYPrN4IaXNXcvJJvpq/e gsHHkCggGzAU2vXSHWNr6SPXSX6SsgIoas6GR3FrpBgoVRSskyIJ1RZBPgKw7apjSllf rSgV2UsAmz3ehE5UcgkgyyBOq8QXUKI7+t2Vqb59vsj8MnRGQC3s8MM574dXRZ/Vdlij YNwwx4m8vFWi/W3U3mdqsgDgXE3bjA1RO03/Oc2oummJ2weMkU8QXFbQ+9Gat5zEXVNQ /LBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rFILUL0jtfDsUEFL3EAT6tZ5FsaqXgMag0W+ybgD8RQ=; b=fGf7mDqL/hkwOR3cVqsKMLAZn8s9+ke7r6jFOslv6sw2MkemDANyt1boMN3B66Uscw bIfLceu2GZRUuvgFR0Wv7nd+qOREHN8i2WYbE0Caia4KQJ2VSFOSWihFR+fOOpBF+g/U Jd+BCKJGjl9P1quT2QFjF8RVqOxZdZ2Um/fywjQ4lnbFZL3f6rTvdrFsWR1wTD8L9oh8 gclVxDjFDl12h1ROtmocOKU4BeH2K/I+1joxVKyJuOV7RoZYe4IzOuVEE51xc6t6naAH iZtqLTkvPDVGwWXuvawHQhTUq2izgh5QkjcGI9Se/UfW27YmFiXkqAfn/wpx9wwcH5mb ZtJg== X-Gm-Message-State: AJaThX4SkPDf8FlM0Q9CL6TAqxrwAvRwkkjM2mmwpEXYUVUld8M7SDBp FB9yk5SOVvjzBlxkSAk9P83iEQ/y X-Google-Smtp-Source: AGs4zMZ4I/MA9TILQN3GLaoA1p+gcx/LKJtjOWlvexFzhQ7aS6Cju0Z86mvneiUpbVjDsmJSwGprmA== X-Received: by 10.46.56.8 with SMTP id f8mr20649590lja.46.1512953535808; Sun, 10 Dec 2017 16:52:15 -0800 (PST) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com. [209.85.215.51]) by smtp.googlemail.com with ESMTPSA id g80sm2585707ljf.89.2017.12.10.16.52.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Dec 2017 16:52:14 -0800 (PST) Received: by mail-lf0-f51.google.com with SMTP id c140so10508257lfg.7 for ; Sun, 10 Dec 2017 16:52:14 -0800 (PST) X-Received: by 10.46.23.156 with SMTP id 28mr17640501ljx.3.1512953534231; Sun, 10 Dec 2017 16:52:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.170.16 with HTTP; Sun, 10 Dec 2017 16:51:53 -0800 (PST) Date: Mon, 11 Dec 2017 01:51:53 +0100 X-Gmail-Original-Message-ID: Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Reflection API: Add ->getTerminatedNamespace() method From: andreas@dqxtech.net (Andreas Hennings) ## Background / motivation Currently a number of reflection classes have a method ->getNamespaceName(). The namespace comes in a format that is not straightforward to work with. It requires the root namespace to be treated in a special way. $namespace = $relfClass->getNamespaceName(); $shortname = $reflClass->getShortName(); $class = $reflClass->getName(); if ('' === $namespace) { assert($class === $namespace . $shortname); assert($class === $shortname); assert($class !== $namespace . '\\' . $shortname); } else { assert($class === $namespace . '\\' . $shortname; assert($class !== $namespace . $shortname); } Code that deals with namespaces therefore always needs a special case for the root namespace. ## Proposal I propose that reflection components that currently have a ->getNamespaceName() method get another method ->getTerminatedNamespace(). This comes with ending namespace separator, unless it is the root namespace. namespace Acme\Animal; class Cat {} assert('Acme\Animal\\' === (new \ReflectionClass(Cat::class))->getTerminatedNamespace()); assert('Acme\Animal' === (new \ReflectionClass(Cat::class))->getNamespaceName()); assert('' === (new \ReflectionClass(\stdClass::class))->getTerminatedNamespace()); assert('' === (new \ReflectionClass(\stdClass::class))->getNamespaceName()); foreach ([Cat::class, \stdClass::class] as $class) { $reflClass = new \ReflectionClass($class); assert($reflClass->getName() === $reflClass->getTerminatedNamespace() . $reflClass->getShortName()); } This would allow all cases to be covered by the same logic.