By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

autoload does not call class

P: 59
Expand|Select|Wrap|Line Numbers
  1.  
  2. function __autoload($class){
  3.  
  4.   include(trim(str_replace('_','/',$class)).'.php';
  5.   if(class_exist){ echo 'my class exists\n'; }
  6.  throw new Exception('class cannot be loaded');
  7. }
  8.  
  9. try{
  10.   new dir_to_myclass();
  11. }catch(exception $e){
  12.   echo $e->getmessage();
  13. }
  14.  
dir/to/myclass.php
Expand|Select|Wrap|Line Numbers
  1.  
  2. echo "here<br/>";
  3.  
  4. class mycalss {
  5.  
  6.   public function __contruct { echo 'myclass instatiated'; }}
  7.  
outputs:
myclass exists
here
class cannot be loaded

why is autoload not instatiating myclass?
Oct 9 '11 #1
Share this Question
Share on Google+
2 Replies


YarrOfDoom
Expert 100+
P: 1,247
Because you misspelled "myclass" in dir/to/myclass.php?
I've also got a feeling it's going to try to create a dir_to_myclass-object rather than a myclass-object.
Oct 10 '11 #2

P: 59
thanks YarrofDoom i got it working i removed the try,catch block and it works just fine i dont know why a try block should stop autoloader from calling the class
Oct 13 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.