1
I’m having an error using the autoloader.
Autoloader.php file:
<?php
function carregarClasses($classe) {
require_once __DIR__ . '/' . $classe . '.php';
}
spl_autoload_register('carregarClasses');
Error:
Warning: require_once(/home/neowix/public_html/Erp/pages/classes/Conexao.php): failed to open stream: No such file or directory in /home/neowix/public_html/Erp/pages/classes/autoload.php on line 4
Fatal error: require_once(): Failed Opening required '/home/neowix/public_html/Erp/pages/classes/Conexao.php' (include_path='.:/opt/php56/lib/php') in /home/neowix/public_html/Erp/pages/classes/autoload.php on line 4
Sorry, I don’t understand where the bug is. The filenames are correct. I believe something is missing in line 4 which is: require_once DIR . '/' . $class . '. php';
– Marcelo
The question is uncertain and depends on N factors, of which I have described 2 of the most obvious. The PHP error message is clear and displays the path you tried to load. Just make sure the path is correct. It is no use to say that it is correct because if it were really correct it would not present this error message. Additionally, check the case sensitive issue, i.e., upper and lower case letters in the file and directory nomenclature. It is well described in the answer. I stress that the problem may have another cause, but I bet on these 2 more logical possibilities.
– Daniel Omine
I checked the paths and they are correct. I think the problem is how I am using this require_once to call the file. From what I saw the problem is in: Warning: require_once(/home/neowix/public_html/Erp/pages/classesConexao.php) A bar is missing after the "classes". How do I put this bar in the require_once?
– Marcelo
I solved it. I was really in trouble. It was .class.php and not only . php in require_once. Thank you.
– Marcelo