On Aug 23 2024, at 12:35 pm, Stephen Reay <php-li...@koalephant.com> wrote:
>
> > would find it non-sensical that you must add a backslash for the engine to 
> > do the "right thing" (in this case, optimize their code with a security 
> > benefit), vs just doing the right thing by default.
>
> What do you mean by this? What is "the right thing"?
I mean this:
<?php
// something.php
namespace App\Models;

function password_hash(string $password, string|int|null $algo, array $options 
= []): string
{
print("Hello");
return $password;
}

<?php
// my code
namespace App\Models;

include "something.php";
password_hash('foobar', PASSWORD_DEFAULT);
This code IMO shouldn't print "Hello", but it does. The current behavior of 
looking up the local namespace first for functions, instead of the global 
namespace first, IMO is the "wrong thing" because it expects developers to 
fully qualify internal function calls every single time because, under very 
specific legitimate use cases that are pretty rare in the course of normal 
development, you actually might want to do that.
> I'm not saying that isn't necessarily how people think, I have literally zero 
> data about this besides my own thoughts, but it seems like a bizarre idea 
> that people would *expect* function name resolution to work completely 
> opposite to how class/class-like name resolution works.
>

At it's core a vast majority of the functionality of the PHP language exists 
within internally-implemented functions, not classes. So yes, I think it's 
entirely reasonable that people would expect that internal functions resolve at 
a higher priority than user-defined functions with the same name, and that if 
you'd like to reuse a global namespaced function in your local namespace you 
need to be explicit about that -- not the other way around.

Reply via email to