Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

composer autoload not work with global funtion

i have in my composer.json:

 "autoload": {
    "files": [
      "test.php"
    ]
  }

the content of test.php is:

<?php

function foo(){
    echo 'Hello World';
}

in my index.php i have this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';

foo();

but i get Call to undefined function foo()

everything that is declared as a file in the autoload is supposed or expected to be added… in this case I expected it to work as a require_once, what am I doing wrong??

Update

after several attempts; the IDE suggests me to use this:

use function /foo

This was not necessary before…

>Solution :

This happens because you have surely declared a namespaces in your test.php; if you remove the namespace it will stop indexing your methods under a namespace and they will remain public/global, I don’t know if this is documented somewhere… but it had already happened to me.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading