Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89622 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32344 invoked from network); 4 Dec 2015 16:52:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Dec 2015 16:52:49 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wm0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:34248] helo=mail-wm0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/F2-09187-0E4C1665 for ; Fri, 04 Dec 2015 11:52:48 -0500 Received: by wmvv187 with SMTP id v187so83317236wmv.1 for ; Fri, 04 Dec 2015 08:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=UFk4uxFCGJu9Y18jfyKjDmSVzH9NQm0zFwyZ5pZsGWU=; b=xIBypCWVp6Q0wkXWLqOZU7xa3X+5dLlrJ4XvjAT/StyVB5ERvBo5YCPjbMTfbK480H gQLGFkjhzV1zWcjfaXwt0EUcZWZo//OV/7ucQ1yZD1CKrGu2uGh8gUF8QX6ccfj8I4jr /2efgQ7t/qs/lAoNdCcR+y7nIXneDx73xg7EqicXmZCbjNAQs0XNBE+x/tPNPLt0D2kv bb9w4KfJtsBKk/fnc1bG/8pkFtATnYzfFxSMd4hvT56S8Ynygkv7Frh0qkyQdrVwAONd BZVnl7yG5Pq4O1YjGkFbzhk7wNwL4+OcTVUdgjikPU8JVgNAyUz3o03qTMO+RUw5LqBN ilDA== MIME-Version: 1.0 X-Received: by 10.194.52.68 with SMTP id r4mr17949106wjo.8.1449247964896; Fri, 04 Dec 2015 08:52:44 -0800 (PST) Received: by 10.28.226.10 with HTTP; Fri, 4 Dec 2015 08:52:44 -0800 (PST) In-Reply-To: References: Date: Fri, 4 Dec 2015 11:52:44 -0500 Message-ID: To: Scott Arciszewski Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Namespaces From: ircmaxell@gmail.com (Anthony Ferrara) Scott, On Fri, Dec 4, 2015 at 11:26 AM, Scott Arciszewski wrote: > Hi, > > It has been brought to my attention that my consistent use of \ prefixing > of global functions is an eyesore, but I've got a simple little PoC that > shows why I do it, and now I'm wondering if the behavior I'm working around > should qualify as a PHP bug? > > https://3v4l.org/po925 > > Scott Arciszewski > Chief Development Officer > Paragon Initiative Enterprises It's not a bug. It's explicit. The `\` prefix says it's a global function. The non-prefixed looks in the current namespace and then falls back to global. Also, in PHP 5.6+ you can do something slightly different to achieve the same result: use function. namespace Foo { use function random_int; var_dump(random_int(1, 100)); var_dump(\random_int(1, 100)); } That will always behave the same no matter if someone defines a namespace-specific random_int function, it will always use the global version. https://3v4l.org/cR6Gg This actually opens a pretty interesting edge-case, where you can define a function in the namespace and use the global one without needing a "\". namespace Foo { use function strlen; function strlen(string $str) : int { return strlen($str) + 1; } } That actually is not recursive. This is a bit non-obvious, but completely follows the rules set forth. So I don't think there's a bug (though we may want to raise a notice in that collision case)... Anthony