Beste,

ik gebruik een wegserver van Apache/2.4.18 en PHP/7.0.2 op mijn macbooktpro
Nu ben ik een cursus aan het volgen van udemy. maar op een punt komt ik een error tegen :
Fatal error: require_once(): Failed opening required 'Core.php'
kan dit aan de versie van php liggen ?

index.php
<script>
<?php
require_once('inc/autoload.php');

$core1 = new Core();
$core1->run();
?>
</script>

autoload.php
<script>
<?php
require_once('_config.php');

function __autoload($class_name) {
$class = explode("_", $class_name);
$path = implode("/", $class).".php";
require_once($path);
}
?>
</script>

_config.php
<script>
<?php

if(!isset($_SESSION)) {
session_start();
}
// site domain name with http
defined("SITE_URL")
|| define("SITE_URL", "http://".$_SERVER['SERVER_NAME']);

// directory separator
defined("DS")
|| define("DS", DIRECTORY_SEPARATOR);

// root path
defined("ROOT_PATH")
|| define("ROOT_PATH", realpath(dirname(__FILE__).DS."..".DS));

// classes folder
defined("CLASSES_DIR")
|| define("CLASSES_DIR", "classes");

// pages directory
defined("PAGES_DIR")
|| define("PAGES_DIR", "pages");

// modules folder
defined("MOD_DIR")
|| define("MOD_DIR", "mod");

// inc folder
defined("INC_DIR")
|| define("INC_DIR", "inc");

// template folder
defined("TEMPLATE_DIR")
|| define("TEMPLATE_DIR", "template");

// emails path
defined("EMAILS_PATH")
|| define("EMAILS_PATH", ROOT_PATH.DS."emails");

// catalogue images path
defined("CATALOGUE_PATH")
|| define("CATALOGUE_PATH", ROOT_PATH.DS."media".DS."catalogue");

// add all above directories to the include path

set_include_path(implode(PATH_SEPARATOR, array(
realpath(ROOT_PATH.DS.CLASSES_DIR),
realpath(ROOT_PATH.DS.PAGES_DIR),
realpath(ROOT_PATH.DS.MOD_DIR),
realpath(ROOT_PATH.DS.INC_DIR),
realpath(ROOT_PATH.DS.TEMPLATE_DIR),
get_include_path()
)));

?>
</script>

Core.php
<script>
<?php

class core {

public function run() {
echo "hi from within run method";
}
}

?>
</script>

Kan iemand mij hier bij helpen ?
met vriendelijke groeten
Johan

[size=xsmall]Toevoeging op 28/08/2016 12:08:14:[/size]

als ik deze uitvoer krijg ik de melding:
Warning: require_once(Core.php): failed to open stream: No such file or directory in /Users/JohanCuypers/Sites/Udemy/inc/autoload.php on line 7


Fatal error: require_once(): Failed opening required 'Core.php' (include_path='/Users/JohanCuypers/Sites/Udemy/classes:/Users/JohanCuypers/Sites/Udemy/pages:/Users/JohanCuypers/Sites/Udemy/mod:/Users/JohanCuypers/Sites/Udemy/inc:/Users/JohanCuypers/Sites/Udemy/template:.:/usr/local/php5/lib/php') in /Users/JohanCuypers/Sites/Udemy/inc/autoload.php on line 7
- SanThe - op 28/08/2016 12:52:39

Hou je hier ook rekening mee?


Let op:
Als je in een bestand een ander bestand include, en in dat andere bestand wil je óók een include gebruiken, dan moet je de include in dat andere bestand zo instellen alsof het door het éérste bestand wordt geinclude.
heb je iets moeten aanpassen ?


Precies wat er staat : Core.php naar map classes verplaatst.

[size=xsmall]Toevoeging op 28/08/2016 13:41:34:[/size]

Ik heb niet alle bestanden dus ik weet niet wie/wat deze functie aanroept in autoload.php :

function __autoload($class_name)


Misschien zit daar de fout.
Adoptive Solution op 28/08/2016 13:32:49

heb je iets moeten aanpassen ?


Precies wat er staat : Core.php naar map classes verplaatst.


als ik dit doe krijg ik die error dus denk iets met instellen van de wegserver ?

er zijn nog ander die dit probleem hebben :> dit staat in de hulp van de instructor:
Hi Sebastian,

after setting config.php and Core class I tried running the app and got following error:

Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

Fatal error: Unknown: Failed opening required '/opt/lampp/htdocs/ecommerce/index.php' (include_path='.:/opt/lampp/lib/php') in Unknown on line 0

what could be the possible falw??

not able to figure out!!

Follow Responses


Sebastian — Instructor · 2 years ago Answer
Hi Atul,

It looks like some conflict with your server setup and the include path.

Try to rename config.php file to _config.php and then change its name in the autoloader.php - where you require it - see if that works.


Maar als ik naam wijzig maak geen verschil

[size=xsmall]Toevoeging op 28/08/2016 17:44:01:[/size]

Na het installeren van MAMP pro werkt deze wel :)

Reageren