zeusthegreat Posted May 3, 2011 Report Share Posted May 3, 2011 (edited) index_auto.php <?php define('APPLICATION_PATH', realpath('../')); $paths = array( APPLICATION_PATH, get_include_path() ); set_include_path(implode(PATH_SEPARATOR, $paths)); function _autoload($className) { require_once $className .'.php'; return; } //var_dump(get_include_path()); //require_once ('user.php'); $User = new User(); echo $User->getName(); class.php<?php class User { public function getName() { return "John smith"; } } ?> methodically went through video and only came across problems towards the end. when i wrote this code and viewed it would not work require_once $className .'.php'; return; it returns from browser Fatal error: Class 'User' not found in C:\wamp\www\coedelobster\video2\index_auto.php on line 19 have no ideas perhaps i have been doing too much and brain scrambled!!!! Edited May 3, 2011 by talos Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 3, 2011 Report Share Posted May 3, 2011 I think the "autoload" function needs two "_" before the function name, not one: http://php.net/manual/en/language.oop5.autoload.php. Try that and see if it fixes things. Quote Link to comment Share on other sites More sharing options...
zeusthegreat Posted May 4, 2011 Author Report Share Posted May 4, 2011 what do you mean ben i have tryed below <?php define('APPLICATION_PATH', realpath('../')); $paths = array( APPLICATION_PATH, get_include_path() ); set_include_path(implode(PATH_SEPARATOR, $paths)); function _"autoload($className) { require_once $className . '.php'; return; } //var_dump(get_include_path()); //require_once ('user.php'); $User = new User(); echo $User->getName(); and <?php define('APPLICATION_PATH', realpath('../')); $paths = array( APPLICATION_PATH, get_include_path() ); set_include_path(implode(PATH_SEPARATOR, $paths)); function "_"autoload($className) { require_once $className . '.php'; return; } //var_dump(get_include_path()); //require_once ('user.php'); $User = new User(); echo $User->getName(); error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or '(' in C:\wamp\www\coedelobster\video2\index.php on line 10 just where has it got to go I think the "autoload" function needs two "_" before the function name, not one: http://php.net/manua...5.autoload.php. Try that and see if it fixes things have had a look on http://uk.php.net/autoload and what i have written looks fine, but i am no expert at all thanks for your help ben do not want to go on until i have mastered everything, and i will not let it beat me, done the lesson twice now with exact same result. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 4, 2011 Report Share Posted May 4, 2011 This line: function _"autoload($className) needs to use two underscores, not one. And no quotes are needed: function __autoload($className) Quote Link to comment Share on other sites More sharing options...
zeusthegreat Posted May 4, 2011 Author Report Share Posted May 4, 2011 sorted thanks again ben Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.