Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: serialize a obiekt
Forum PHP.pl > Forum > PHP
aleksander
Witam,

mam następujące kody ( do robienia pliku konfiguracyjnego w xml ):
  1. <?php
  2. class ConfigParser
  3. {
  4. private $config;
  5.  
  6. public function __construct()
  7. {
  8. $this -> loadConfig();
  9. }
  10.  
  11.  
  12. public function loadConfig()
  13. {
  14. if( filemtime( 'config.php' ) < filemtime( 'config.xml' ) )
  15. {
  16. $this -> parseConfig();
  17. } else {
  18. $this -> config = unserialize( file_get_contents( 'config.php' ) ); // linia 18
  19. }
  20.  
  21. }
  22.  
  23. public function parseConfig()
  24. {
  25. $this -> config = simplexml_load_file( 'config.xml' );
  26. file_put_contents( 'config.php', serialize( $this -> config) );
  27.  /* echo '<pre>';
  28. var_dump( $this -> configFile );
  29. echo '</pre>';  */
  30. }
  31. // Kilka metod wyciągających poszczególne dane np.:
  32. public function getPostLoadingModules( $module = false )
  33. {
  34. return $this -> config -> postloadingmodules -> module;
  35. if( $module !== false )
  36. {
  37. if( isset( $this -> config -> postLoadingModules -> module[$path] ) )
  38. {
  39. return $this -> config -> postLoadingModules -> module[$path];
  40. } else {
  41. return false;
  42. }
  43. } else {
  44. return $this -> config -> postloadingmodules -> module;
  45. }
  46. }
  47. }
  48. ?>
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <kernel-config>
  3.  <paths>
  4.    <modules-path>module/</modules-path>
  5.    <auth-path>auth/</auth-path>
  6.  </paths>
  7.  
  8.  <preloadingmodules>
  9.    <module>headery</module>
  10.    <module>menu</module>
  11.    <module>calendar</module>
  12.  </preloadingmodules>
  13.  
  14.  <postloadingmodules>
  15.    <module>stats</module>
  16.    <module>footer</module>
  17.  </postloadingmodules>
  18. </kernel-config>
Cytat("config.php")
O:16:"SimpleXMLElement":3:{s:5:"paths";O:16:"SimpleXMLElement":2:{s:12:"modules-path";s:7:"module/";s:9:"auth-path";s:5:"auth/";}s:17:"preloadingmodules";O:16:"SimpleXMLElement":1:{s:6:"module";a:3:{i:0;s:7:"headery";i:1;s:4:"menu";i:2;s:8:"calendar";}}s:18:"postloadingmodules";O:16:"SimpleXMLElement":1:{s:6:"module";a:2:{i:0;s:5:"stats";i:1;s:6:"footer";}}}

który zwraca następujące błedy:
Cytat("errory")
Warning: unserialize() [function.unserialize]: Node no longer exists in C:\www\xampp\htdocs\engine\config.parser.php on line 18
No i ja po prostu nie wiem co mam z tym zrobić sad.gif
aleksander
@hwao: zauwarz, że SimpleXMLElement jest klasą wbudowaną, nie mogę sobie jej zmieniać.
hawk
http://www.codecomments.com/PHP_XML/message150675.html
http://news.php.net/php.xml.dev/205
Serwer news.php.net chyba wziął sobie akurat wolne, więc sam musisz dojść, czemu tego nie można robić.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.