Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code can't find PHP function - maybe "require_once" syntax?

I would like to switch to Visual Studio Code for PHP development.

All of my files start with require_once with this syntax

require_once(__DIR__ .  DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'common'  . DIRECTORY_SEPARATOR . 'api'  . DIRECTORY_SEPARATOR . 'RequireCommonStuff.php');

and debugging won't launch, presumably because VSC says that there are problems with the file to be debugged, along the lines of

Undefined function 'DumpGetAndPostParametersIfDebugging'.

where that function is declared in one of my required files.

Strangely, there are no problems reported for the require_once statements, but I can think of no other explanation for the function not being found.

The code works just fine with PHPstorm, I am testing on localhost - any ideas as to what I am doing wrongly?


[Update] the error is happenig with every function which is declared in a required file. Here's what leads to the first example.

in RequireCommonStuff.php, I just have more require_onces :

require_once(__DIR__ . DIRECTORY_SEPARATOR . 'constants.php');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'third_party' . DIRECTORY_SEPARATOR .'ChromePhp.php');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'errorHandling.php');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'trace.php');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'parseAndValidateUrlGetParameters.php');

The last of those is causing the error I discuss (although all of them cause erros). It's contents are (note: no classes involved), header comment stripped

function ParseAndValidateUrlGetParameters($url, 
                                         $inputType, 
                                         $filter, 
                                         $debug, 
                                         $reportIndicent=true, 
                                         $allFieldsMandatory=true)
{
like image 910
Mawg says reinstate Monica Avatar asked Mar 02 '23 05:03

Mawg says reinstate Monica


1 Answers

not sure about it but you can install and test PHP Intelephense instead of Intellisense. also check if php path is added in vscode "php.validate.executablePath".

like image 121
omid Avatar answered Mar 05 '23 16:03

omid