composer: Problem on load namespaced functions
Composer don`t load function inside namespaces, like is written in php manual.
https://www.php.net/manual/en/language.namespaces.basics.php
project structure:
—root |—src |—Hello |—echo.php |—World |—Name.php |—vendor index.php composer.json
//composer.json
{
"name": "igor/phpnamespacetest",
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"authors": [
{
"name": "Igor de Paula",
"email": "************@gmail.com"
}
],
"require": {}
}
//index.php
<?php
require('vendor/autoload.php');
$w = new \App\World\Name();
$w->eco('Hi');
//echo.php
<?php
namespace App\Hello;
function eco($t){
echo $t;
}
//Name.php
<?php
namespace App\World;
use function App\Hello\eco;
class Name
{
public function eco($t)
{
eco($t);
}
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 38 (19 by maintainers)
Please @yesdevnull , @PrinsFrank , @eliashaeussler , @digitalgrease , @pankali , @rafaelstz , @greew , @kubawerlos , @staabm , @jeffwidman , @zanbaldwin , @ralflang , @dmitryuk
@IgorDePaula Please don’t tag random contributors because you don’t get the answer you want. Now a bunch of people got a notification and are automatically subscribed to this thread. Is this thread really what you want other open source developers to remember about you? Please be kind and accepting when some of the smartest people in the PHP community give you an answer and try to help you, even if you don’t like that answer.
You keep on saying that the PHP documentation says something about loading - it does not!
Number of times the word load or autoload is mentioned in the following links:
The <?php use ?> statement does not load the class file. You have to do this with the <?php require ?> statement or by using an autoload function.
(https://www.php.net/manual/en/language.namespaces.importing.php#114265).You also keep on saying that the PHP documentation mentions using filesystem for loading namespace functions - it also does not.
https://www.php.net/manual/en/language.namespaces.basics.php:
The filesystem text you keep mentioning does not say anything about that you can load the namespaced stuff. Actually this is the same for for the filesystem itself, that you keep mentioning. By entering the filename in a simple text editor or a command line, the file will not be loaded. You will have to use a program to open the file. This is the same in PHP - you have to load the namespaced stuff into the file first. This usually happens with
include
or one of it’s friendsrequire
,include_once
,require_once
.But instead of having to manually load all files that you have to use, the PHP core have added a function called
spl_autoload_register()
. As the documentation on that page says, it’s about autoloading classes - NOT functions.That might be how you think it should be, but since the majority of the GitHub community does not see it this way, you’re taking a bad approach by just referencing a bunch of random people.
I hope you will go through this and my previous comments and actually try and read AND understand, what is being written.
Autoloading functions would be a wonderful addition to PHP! @IgorDePaula if they’re not working how you think they should, you should make a pull request on https://github.com/php/php-src to add them! A PR for the docs to make those pages more understandable would also be a wonderful contribution 😃
You know what happens to that cocky attitude? A competitor is born. Not from me, since to you I’m dumb and ignorant. But someone does.
Yes, admitting that there is a mistake takes courage.
Composer is not conform to php.
Your options are up there https://github.com/composer/composer/issues/11291#issuecomment-1416277570
@IgorDePaula You clearly chose to ignore what @zanbaldwin said before:
Of the two links you provided to the PHP core, neither of them tells us anything about autoloading. They only show us how to deal with namespaced classes, function and constants when they have already been loaded, either by already being in the same file as the calling code, by being loaded by
require
/import
or by usingspl_autoload_register
.If you take a look at https://www.php.net/manual/en/language.oop5.autoload.php you will see that this is very precisely called “Autoloading Classes”. There is no mention of autoloading functions or consts. Actually, the comment https://www.php.net/manual/en/language.oop5.autoload.php#124770 tells us as the first thing, that autoloading functions is not supported in PHP.
You now ask us to provide a PoC or technical article about how this is NOT possible?
You also say, you have showed us something concrete. Good - I have now taken those same two documentation articles and shown you even another one, that shows us, that what you say can be accomplished, is not supported in PHP.
@greew People said yes, but without PoC, or technical article, I still showed something, something concrete, the php manual, but nobody showed anything but their own words. If php doesn’t support namespaced functions, why does it have that in the manual? Clearly there is a fault here, and it’s not mine.
@IgorDePaula
You’ve been told multiple times now, that PHP doesn’t support autoloading of namespaced functions. You’ve been told multiple times that Composer doesn’t support autoloading of namespaced functions because PHP doesn’t support it.
You keep on saying, that you think Composer has a bug, because you think the PHP documentation says otherwise.
THEN: If you actually believe, that PHP does support autoloading of namespaced functions, please show us an example of how you would achieve this without using Composer. If you actually are able to do this, then we might get into a discussion about it, but until then I’m outta here!
See https://getcomposer.org/doc/01-basic-usage.md#autoloading and https://getcomposer.org/doc/04-schema.md#autoload for classes.
Functions do not trigger the autoloader so cannot be autoloaded. I’m unsubscribing from this thread as I feel like you are not willing to listen.
By this reason this is a bug, not follow php pattern.