Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]Błąd w skrypcie z książki
HaMtAr0
post
Post #1





Grupa: Zarejestrowani
Postów: 25
Pomógł: 0
Dołączył: 29.12.2006

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


Witam!
Uczę się programowania w php, mam książkę "Php i Mysql - aplikacje bazozadaniowe", razem z książką był zamieszczony kod który znajduje się w książce..
Jednak po jego odpaleniu występuje błąd:
  1. <?php
  2. Catchable fatal error: Object of class winestoreTemplate could not be converted to string in /home/adam/public_html/workspace/przyklady_ksiazki/wda2-winestore/includes/customHandler.inc on line 44
  3. ?>

Cały plik:
  1. <?php
  2. // Source code example for Web Database Applications with PHP and MySQL, 2nd Editi
    on
  3. // Author: Hugh E. Williams, 2001-3
  4. // 
  5. // Unless otherwise stated, the source code distributed with this book can be
  6. // redistributed in source or binary form so long as an acknowledgment appears
  7. // in derived source files.
  8. // The citation should list that the code comes from Hugh E. Williams and David 
  9. // Lane, "Web Database Application with PHP and MySQL" published by O'Reilly & 
  10. // Associates.
  11. //
  12. // This code is under copyright and cannot be included in any other book,
  13. // publication, or educational product without permission from O'Reilly &
  14. // Associates. No warranty is attached; we cannot take responsibility for errors 
  15. // or fitness for use.
  16.  
  17. require_once "winestore.inc";
  18.  
  19. // Back trace an error
  20. function backTrace($context)
  21. {
  22.  $calls = "";
  23.  
  24.  // Get a backtrace of the function calls
  25.  $trace = debug_backtrace();
  26.  
  27.  $calls = "\nBacktrace:";
  28.  
  29.  // Start at 2 -- ignore this function (0) and the customHandler() (1)
  30.  for($x=2; $x < count($trace); $x++)
  31.  {
  32.  $callNo = $x - 2;
  33.  $calls .= "\n {$callNo}: {$trace[$x]["function"]} ";
  34.  $calls .= "(line {$trace[$x]["line"]} in {$trace[$x]["file"]})";
  35.  }
  36.  
  37.  $calls .= "\nVariables in {$trace[2]["function"]} ():";
  38.  
  39.  // Use the $context to get variable information for the function
  40.  // with the error
  41.  foreach($context as $name => $value)
  42.  {
  43.  if (!empty($value))
  44.  $calls .= "\n {$name} is {$value}";
  45.  else
  46.  $calls .= "\n {$name} is NULL";
  47.  }
  48.  return ($calls);
  49. }
  50. // Custom error handler function -- reproduced from Chapter 12
  51. function customHandler($number, $string, $file, $line, $context)
  52. {
  53. $error = "";
  54.  
  55. switch ($number)
  56. {
  57.  case E_USER_ERROR:
  58.  $error .= "\nERROR on line {$line} in {$file}.\n";
  59.  $stop = true;
  60.  break;
  61.  case E_WARNING:
  62.  case E_USER_WARNING:
  63.  $error .= "\nWARNING on line {$line} in {$file}.\n";
  64.  $stop = false;
  65.  break;
  66.  case E_NOTICE:
  67.  case E_USER_NOTICE:
  68.  $error .= "\nNOTICE on line {$line} in {$file}.\n";
  69.  $stop = false;
  70.  break;
  71.  default:
  72.  $error .= "UNHANDLED ERROR on line {$line} in {$file}.\n";
  73.  $stop = false;
  74. }
  75. $error .= "Error: \"{$string}\" (error #{$number}).";
  76. $error .= backTrace($context);
  77. $error .= "\nClient IP: {$_SERVER["REMOTE_ADDR"]}";
  78.  
  79. $prepend = "\n[PHP Error " . date("YmdHis") . "]";
  80. $error = ereg_replace("\n", $prepend, $error);
  81.  
  82. if (SCREEN_ERRORS)
  83.  print "<pre>{$error}</pre>";
  84.  
  85. if (FILE_ERRORS)
  86.  error_log($error, 3, ERROR_FILE);
  87.  
  88. if ($stop == true)
  89. {
  90. if (isset($_SESSION["order_no"]))
  91.  unset($_SESSION["order_no"]);
  92.  
  93.  if (isset($_SESSION["loginUsername"]))
  94. unset($_SESSION["loginUsername"]);
  95.  
  96.  if (isset($_SESSION["loginIP"]))
  97. unset($_SESSION["loginIP"]);
  98.  
  99. die(); 
  100. }
  101. }
  102.  
  103. ?>

Interesuje mnie czy błąd dotyczy jednej pętli? Czy cały skrypt jest niekompatybilny z nową wersją php?

Ten post edytował HaMtAr0 12.08.2007, 15:59:46
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: 25.12.2025 - 01:37