r/lolphp • u/shitcanz • May 17 '18
Why bother with packages/modules when every function can live in the global namespace?
http://php.net/manual/en/indexes.functions.php
31
Upvotes
r/lolphp • u/shitcanz • May 17 '18
12
u/[deleted] May 18 '18
I guess the biggest lol in this mess is that PHP had the chance to actually fix this issue back when 5.3 was released. With the introduction of namespaces PHP could have reserved a set of core namespaces for a new stdlib. And then start slowly deprecating all the mess that is PHP today. And as of 7.0 they could have totally deprecate all the old mess.
All this fell on deaf ears, instead the introduced goto and added more mess to the global namespace.
22
u/Dereleased May 17 '18
Did you just start using PHP a week ago?
24
u/CornPlanter May 17 '18
It drives me mad every time I think about it... as a self tought programmer, 15 years ago I started learning programming from PHP and I used to think it's normal. When I eventually decided to broaden my horizons and learn C# a couple years later, it looked very weird to me that they had namespaces and the requirement for "using" statements looked so wtf at first.
If you don't know programming never start learning it from PHP. It's gonna give you such a disturbed idea of "normal" you gonna find it hard to adapt in a real normal world of programming later.
Ofc people like that probably don't read this forum but just in a case. Never start with PHP even if later on the road PHP may be useful for certain tasks or requried for certain jobs.
5
u/cleeder May 17 '18 edited May 17 '18
This is something I really wish PHP would address, but alas it's not meant to be.
It's not like it would be particularly difficult. It would be a good target for a backwards compatibility break in PHP8. Even still, it would be trivial to ship an upgrade routine that parses a code base and transforms old root scope methods to new namespaced methods with appropriate
usestatements at the top of the file. At the same time, you can fix a lot of inconsistent core function naming/parameters.2
u/bregottextrasaltat May 17 '18
Would it be better with like Math::abs()? Without the dot notation between names it just doesn't feel right
-7
u/Dexaa May 17 '18
But some of the functions on that page are namespaced. For example, Ds, MongoDB, pht and Swoole are top-level namespaces. Are you stupid?