Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Exception, __autoload, error_handler
koala
post
Post #1





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 4.03.2005

Ostrzeżenie: (0%)
-----


Witam !
W pliku index.php mam m.in. :
  1. <?php
  2. set_exception_handler('exception_handler');
  3. set_error_handler('error_handler');
  4. function exception_handler( $e )
  5. {
  6. echo '<b>Exception :</b><br />';
  7. echo 'komunikat => '.$e->getMessage().'<br />';
  8. echo 'plik => '.$e->getFile().'<br />';
  9. echo 'linia => '.$e->getLine().'<br />';
  10.  
  11. } // end : function exception_handler();
  12.  
  13. function error_handler($severity, $message, $filepath, $line)
  14. {
  15. echo '$severity - '.$severity.'<br />';
  16. echo '$message - '.$message.'<br />';
  17. echo '$filepath - '.$filepath.'<br />';
  18. echo '$line - '.$line.'<br />';
  19.  
  20. } // end : function error_handler();
  21.  
  22. require( DIR_LIB.'ccc'.EXT );
  23.  
  24.  
  25. function __autoload( $class )
  26. { 
  27. echo '1. Klasa - '.$class.'<br />';
  28. CCC::loadClass( $class );
  29. } // end : function __autoload($class);
  30.  
  31. $config = CCC_Config::get_instance();
  32. ?>

Klasa CCC_Config istnieje i ładuje ją jak trzeba.
Klasy CCC_Router nie ma, istnieje pusty plik router.php i po takiej próbie wczytania :
  1. <?php
  2. $router = CCC::loadClass( 'CCC_Router' );
  3. ?>

dostaję prawidłowy komunikat :
  1. Exception :
  2. komunikat => Plik Router.php załadowany ale nie ma w nim klasy => CCC_Router
  3. plik => E:\xampp\xampp\htdocs\jg\lib\ccc.php
  4. linia => 91

jeśli spróbuję ją wczytać przez __autoload :
  1. <?php
  2. $router = new CCC_Router;
  3. ?>

dostaję taki komunikat :
  1. Fatal error: Class 'CCC_Router' not found in E:\xampp\xampp\htdocs\jg\index.php on line 137

czyli nie dość że nie używa mojego error_handler'a to - on line 137 - chociaż ostatnimi znakami w tym pliku są w lini 136 -> "?>", po nich nie ma nawet spacji.
Jeśli nie ma nawet pliku router.php to mam taki komunikat :
  1. 1. Klasa - CCC_Router
  2. 2. Klasa - CCC_Router
  3. Fatal error: Class 'CCC_Router' not found in E:\xampp\xampp\htdocs\jg\index.php on line 137

czyli znowu ani error_handler ani exception_handler. Coś chyba robię nie tak ale już nie wiem co.
no i jeszcze metoda loadClass z klasy CCC :
  1. <?php
  2. static public function loadClass( $class )
  3. {
  4.  if( preg_match( '/[^a-z0-9-_.]/i', $class ) )
  5. {
  6. throw new Exception('Security : Nielegalne znaki w nazwie klasy');
  7. }
  8.  
  9. if( class_exists( $class, false ) )
  10. {
  11. echo "Klasa ".$class." już załadowana<br />";
  12. return;
  13. }
  14.  
  15. // Zamiana nazwy klasy na ścieżkę
  16. $path = str_replace('_', DIRECTORY_SEPARATOR, $class);
  17. if( $path != $class )
  18. {
  19. $dirs = dirname( $path );
  20. $file = basename( $path ).EXT;
  21. }
  22. else
  23. {
  24. $file = $class.EXT;
  25. }
  26.  
  27. if( file_exists( DIR_APP_LIB.$dirs.'/'.$file ) )
  28. {
  29. require( DIR_APP_LIB.$dirs.'/'.$file );
  30. }
  31. else
  32. {
  33. if( file_exists( DIR_LIB.$dirs.'/'.$file ) )
  34. {
  35. require( DIR_LIB.$dirs.'/'.$file );
  36. }
  37. else
  38. {
  39. echo '2. Klasa - '.$class.'<br />';
  40. throw new Exception('Pliku '.$file.' nie znalazłem');
  41. }
  42. }
  43.  
  44. if( ! class_exists( $class, false ) )
  45. {
  46. throw new Exception( 'Plik '.$file.' załadowany '
  47.  . 'ale nie ma w nim klasy => '.$class );
  48. }
  49.  
  50. } // end : public static function loadClass();
  51. ?>

To że pokazuje się 2. Klasa CCC_Router oznacza, jest w metodzie loadClass, (według mnie) że powinno wyświetlić komunikat z exception_handler'a bo do tego miejsca dochodzi a jednak Fatal error i to nawet nie z mojego error_handlera. Bardzo proszę o jakąś podpowiedź co zrobiłem nie tak ?

Zmieniając w loadClass na :
  1. <?php
  2. if( file_exists( DIR_APP_LIB.$dirs.'/'.$file ) )
  3. {
  4. require( DIR_APP_LIB.$dirs.'/'.$file );
  5. }
  6. else
  7. {
  8. require( DIR_LIB.$dirs.'/'.$file );
  9. }
  10. ?>

przy braku pliku router.php mam taki komunikat :
  1. 1. Klasa - CCC_Config
  2. 1. Klasa - CCC_Router
  3. $severity - 2
  4. $message - CCC::require(E:/xampp/xampp/htdocs/jg/lib/CCC/Router.php) [function.CCC-require]: failed to open stream: No such file or directory
  5. $filepath - E:\xampp\xampp\htdocs\jg\lib\ccc.php
  6. $line - 78
  7.  
  8. Fatal error: CCC::require() [function.require]: Failed opening required 'E:/xampp/xampp/htdocs/jg/lib/CCC/Router.php' (include_path='.;E:\xampp\xampp\php\pear') in E:\xampp\xampp\htdocs\jg\lib\ccc.php on line 78

natomiast jeśli jest pusty plik router.php
  1. Fatal error: Class 'CCC_Router' not found in E:\xampp\xampp\htdocs\jg\index.php on line 137


Ten post edytował koala 23.10.2006, 17:20:27
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 13:04