0

main.php requires 2 files:

require './functions/fileA.php';
require './functions/fileB.php';

fileA.pgp as a function

function doecho($url){echo $url}

In fileB.php, I have a function that calls the doecho function

function withinBfunction($url){doecho($url);}

But I get this error,

Uncaught Error: Call to undefined function curl().

However, if, in fileB.php I call the doecho function outside any function, it works. It seems that the functions in fileB.php cannot access the functions on fileA.php

I took a look at this post (PHP Fatal error: Call to undefined function when function is defined) but the difference is that I am not using classes. Any ideas how I could solve this?

Oh, and, yes, I have turned on the php error log with (error_reporting(E_ALL & ~E_NOTICE & E_STRICT & ~E_DEPRECATED) and all I get is that "call to undefined function".

Dinis
  • 11
  • 1
  • 4
  • 9
    `include` does not die if the file can't be loaded. use `require` to make sure the file is loaded correctly. – Dormilich Mar 29 '18 at 11:41
  • Are you sure that `fileA.php` is included? Maybe the interpreter cannot find it and the warning it triggers is suppressed by your configuration. Use [`require`](http://php.net/manual/en/function.require.php) instead. – axiac Mar 29 '18 at 11:43
  • If PHP says it's not there, it's not there, no matter what you think. – Michel Mar 29 '18 at 11:52
  • May be you are missing one period in `include './functions/fileB.php';`. Try `include '../functions/fileB.php';` – Nagesh Katke Mar 29 '18 at 11:55
  • @Dormilich, I am using require now. Still, no good results.I also a preatymuxh ure that the files are being loaded because I tested some echos and they show up. – Dinis Mar 29 '18 at 12:01
  • maybe you got a namespace defined somewhere? – Jeff Mar 29 '18 at 12:03
  • 1
    display errors would have helped you, try debugging before you ask for help. https://stackoverflow.com/q/5438060/3664960 – davejal Mar 29 '18 at 12:34
  • @dajeval, Thank you for your comment. However I have been looking at the php errors, yes. And all I get is that Uncaught Error: Call to undefined function curl(). That is why I am asking for help here. – Dinis Mar 29 '18 at 13:27
  • @Jeff, thank you for commenting. I am not recalling using namespaces. – Dinis Mar 29 '18 at 13:30
  • @axiac, I changed to require. Same issue. Also nothing helpful shows in the error logs (error_reporting(E_ALL & ~E_NOTICE & E_STRICT & ~E_DEPRECATED)) except the Call to undefined function ... – Dinis Mar 29 '18 at 13:33

1 Answers1

0

I think you should use two dots for one directory up like: Include '../directory name';

  • Hi. Don't think that is the problem. I a using now "require", instead of "include". Both included files are in he same folder. If I put two dots, require fails. – Dinis Mar 29 '18 at 17:18