468,738 Members | 2,633 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

PHP4 -> PHP5 issue

Hi there

I'm quite experienced in programming in PHP4, but I would like to make
a step to PHP5.
I created following class which works perfectly in PHP4 :

Expand|Select|Wrap|Line Numbers
  1. Class Nessi
  2. {
  3. // ident part
  4. var $user = ""; //the username
  5. var $password = ""; //the password
  6.  
  7. // invoice records
  8. var $invoices = array(); //list of invoice records
  9. var $i = -1; //invoice counter
  10.  
  11. // client records
  12. var $clients = array(); //list of client records
  13. var $j = -1; //client counter
  14.  
  15. var $XML = ""; // The XML file content
  16. function OpenFile($filename)
  17. {
  18. // leest de inhoud van een bestand naar een string
  19. $handle = fopen ($filename, "r");
  20. $contents = fread ($handle, filesize ($filename));
  21. fclose ($handle);
  22. $this->XML = $contents;
  23. $this->ParseXML();
  24. }
  25.  
  26. function ParseXML()
  27. {
  28. $doc = xmldoc($this->XML);
  29. $root = $doc->root();
  30. $children = $root->children();
  31.  
  32. foreach($children as $child)
  33. {
  34. if ($child->type == "1")
  35. {
  36. switch ($child->tagname)
  37. {
  38. case "ident":
  39. $this->Ident($child);
  40. break;
  41. case "invoice":
  42. $this->Invoice($child);
  43. break;
  44. case "client":
  45. $this->Client($child);
  46. break;
  47. default: ;
  48. } // switch
  49. }
  50. }
  51. unset($this->XML);
  52. }
  53.  
  54. function Ident($child)
  55. {
  56. $record = $child->children();
  57.  
  58. foreach($record as $item)
  59. {
  60. if ($item->type == "1")
  61. {
  62. if ($item->tagname == "user")
  63. {
  64. $content = $item->children();
  65. $this->user = $content[0]->content;
  66. }
  67. if ($item->tagname == "pass")
  68. {
  69. $content = $item->children();
  70. $this->password = $content[0]->content;
  71. }
  72. }
  73. }
  74. }
  75.  
  76. function Invoice($child)
  77. {
  78. $i = 0;
  79. $this->invoices[++$this->i] = array();
  80. $invoice = $child->children();
  81. foreach($invoice as $invitem)
  82. {
  83. switch ($invitem->tagname)
  84. {
  85. case "header":
  86. $header = $invitem->children();
  87. foreach($header as $headitem)
  88. {
  89. switch ($headitem->tagname)
  90. {
  91. case "clientid" :
  92. $text = $headitem->children();
  93. $this->invoices[$this->i]['clientid'] =
  94. $text[0]->content;
  95. break;
  96. case "clientinfo":
  97. $text = $headitem->children();
  98. $this->invoices[$this->i]['clientinfo']
  99. = $text[0]->content;
  100. break;
  101. case "date":
  102. $text = $headitem->children();
  103. $this->invoices[$this->i]['date'] =
  104. $text[0]->content;
  105. break;
  106. default: ;
  107. } // switch
  108. }
  109.  
  110. break;
  111. case "items":
  112. $items = $invitem->children();
  113. foreach($items as $item)
  114. {
  115. if ($item->type == "1")
  116. {
  117. if ($item->tagname == "item")
  118. {
  119. $content = $item->children();
  120. $newitem['desc'] =
  121. $content[0]->content;
  122. $newitem['price'] =
  123. $item->get_attribute("price");
  124.  
  125. $this->invoices[$this->i]['items'][$i++] = $newitem;
  126. unset($newitem);
  127. }
  128. }
  129. }
  130. break;
  131. default: ;
  132. } // switch
  133. }
  134. }
  135. function Client($child)
  136. {
  137. // not yet implemented...
  138. }
  139. }
  140.  
If I include this class into a script running in PHP5, I only get a
blank output. In fact, the execution seems to stop when including or
instantiating this class. I don't get any error message, even with
error_reporting(E_ALL).

What am I missing ?

Aug 17 '06 #1
7 1510
Mathieu Maes wrote:
Hi there

I'm quite experienced in programming in PHP4, but I would like to make
a step to PHP5.
I created following class which works perfectly in PHP4 :

Expand|Select|Wrap|Line Numbers
  1. Class Nessi
  2. {
  3.     // ident part
  4.     var $user = ""; //the username
  5.     var $password = ""; //the password
  6.     // invoice records
  7.     var $invoices = array(); //list of invoice records
  8.     var $i = -1; //invoice counter
  9.     // client records
  10.     var $clients = array(); //list of client records
  11.     var $j = -1; //client counter
  12.     var $XML = ""; // The XML file content
  13.     function OpenFile($filename)
  14.     {
  15.         // leest de inhoud van een bestand naar een string
  16.         $handle = fopen ($filename, "r");
  17.         $contents = fread ($handle, filesize ($filename));
  18.         fclose ($handle);
  19.         $this->XML = $contents;
  20.         $this->ParseXML();
  21.     }
  22.     function ParseXML()
  23.     {
  24.         $doc = xmldoc($this->XML);
  25.         $root = $doc->root();
  26.         $children = $root->children();
  27.         foreach($children as $child)
  28.         {
  29.             if ($child->type == "1")
  30.             {
  31.                 switch ($child->tagname)
  32.                 {
  33.                     case "ident":
  34.                         $this->Ident($child);
  35.                         break;
  36.                     case "invoice":
  37.                         $this->Invoice($child);
  38.                         break;
  39.                     case "client":
  40.                         $this->Client($child);
  41.                         break;
  42.                     default: ;
  43.                 } // switch
  44.             }
  45.         }
  46.         unset($this->XML);
  47.     }
  48.     function Ident($child)
  49.     {
  50.         $record = $child->children();
  51.         foreach($record as $item)
  52.         {
  53.             if ($item->type == "1")
  54.             {
  55.                 if ($item->tagname == "user")
  56.                 {
  57.                     $content = $item->children();
  58.                     $this->user = $content[0]->content;
  59.                 }
  60.                 if ($item->tagname == "pass")
  61.                 {
  62.                     $content = $item->children();
  63.                     $this->password = $content[0]->content;
  64.                 }
  65.             }
  66.         }
  67.     }
  68.     function Invoice($child)
  69.     {
  70.         $i = 0;
  71.         $this->invoices[++$this->i] = array();
  72.         $invoice = $child->children();
  73.         foreach($invoice as $invitem)
  74.         {
  75.             switch ($invitem->tagname)
  76.             {
  77.                 case "header":
  78.                     $header = $invitem->children();
  79.                     foreach($header as $headitem)
  80.                     {
  81.                         switch ($headitem->tagname)
  82.                         {
  83.                             case "clientid" :
  84.                                 $text = $headitem->children();
  85.                                 $this->invoices[$this->i]['clientid'] =
  86. $text[0]->content;
  87.                                 break;
  88.                             case "clientinfo":
  89.                                 $text = $headitem->children();
  90.                                 $this->invoices[$this->i]['clientinfo']
  91. = $text[0]->content;
  92.                                 break;
  93.                             case "date":
  94.                                 $text = $headitem->children();
  95.                                 $this->invoices[$this->i]['date'] =
  96. $text[0]->content;
  97.                                 break;
  98.                             default: ;
  99.                         } // switch
  100.                     }
  101.                     break;
  102.                 case "items":
  103.                     $items = $invitem->children();
  104.                     foreach($items as $item)
  105.                     {
  106.                         if ($item->type == "1")
  107.                         {
  108.                             if ($item->tagname == "item")
  109.                             {
  110.                                 $content = $item->children();
  111.                                 $newitem['desc'] =
  112. $content[0]->content;
  113.                                 $newitem['price'] =
  114. $item->get_attribute("price");
  115. $this->invoices[$this->i]['items'][$i++] = $newitem;
  116.                                 unset($newitem);
  117.                             }
  118.                         }
  119.                     }
  120.                     break;
  121.                 default: ;
  122.             } // switch
  123.         }
  124.     }
  125.     function Client($child)
  126.     {
  127.         // not yet implemented...
  128.     }
  129. }
  130.  

If I include this class into a script running in PHP5, I only get a
blank output. In fact, the execution seems to stop when including or
instantiating this class. I don't get any error message, even with
error_reporting(E_ALL).

What am I missing ?
I didn't really looked into your code but usually the biggest difference
between objects in php4 and php5 is that all the object variables are
passed by reference in php5 (and I think I've seen you use some of those :)

--

B.r.K.o.N.j.A = Bionic Robotic Knight Optimized for Nocturnal Judo and
Assasination
Aug 17 '06 #2
Is there something in an errorlog (if that is turned on in php.ini)?
Aug 17 '06 #3

Dikkie Dik wrote:
Is there something in an errorlog (if that is turned on in php.ini)?
all errors are usually logged in a file as well... Nothing in there.

This is the script how I use the class :
=======
<pre>
<?php
require "nessi.class.php";
$xml = new Nessi;
$xml = loadfile(invoice.xml);
print_r($GLOBALS);
?>
</pre>
=======

The output of the script is :
<pre>
I really haven't got a clue ...

Aug 17 '06 #4
Does the nessi class code start with <?php ? It may start with <? while
short tags are not configured in php.ini

Mathieu Maes wrote:
Dikkie Dik wrote:
>Is there something in an errorlog (if that is turned on in php.ini)?

all errors are usually logged in a file as well... Nothing in there.

This is the script how I use the class :
=======
<pre>
<?php
require "nessi.class.php";
$xml = new Nessi;
$xml = loadfile(invoice.xml);
print_r($GLOBALS);
?>
</pre>
=======

The output of the script is :
<pre>
I really haven't got a clue ...
Aug 17 '06 #5
Dikkie Dik wrote:
Does the nessi class code start with <?php ? It may start with <? while
short tags are not configured in php.ini

Mathieu Maes wrote:
>Dikkie Dik wrote:
>>Is there something in an errorlog (if that is turned on in php.ini)?

all errors are usually logged in a file as well... Nothing in there.

This is the script how I use the class :
=======
<pre>
<?php
require "nessi.class.php";
$xml = new Nessi;
To instantiate the class Nessi I think it should look like this:
$xml = new Nessi();
>$xml = loadfile(invoice.xml);
print_r($GLOBALS);
?>
</pre>
=======

The output of the script is :
<pre>
I really haven't got a clue ...

--
--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 18 '06 #6
I think this is a server configuration problem.

I usually use <?php ?>, but now I tried with <? ?>. Now the code is
just shown in the output in stead of parsed...

Thanks for all your efforts !

IchBin wrote:
Dikkie Dik wrote:
Does the nessi class code start with <?php ? It may start with <? while
short tags are not configured in php.ini

Mathieu Maes wrote:
Dikkie Dik wrote:
Is there something in an errorlog (if that is turned on in php.ini)?

all errors are usually logged in a file as well... Nothing in there.

This is the script how I use the class :
=======
<pre>
<?php
require "nessi.class.php";
$xml = new Nessi;

To instantiate the class Nessi I think it should look like this:
$xml = new Nessi();
$xml = loadfile(invoice.xml);
print_r($GLOBALS);
?>
</pre>
=======

The output of the script is :
<pre>
I really haven't got a clue ...


--
--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 18 '06 #7
Mathieu Maes wrote:
Dikkie Dik wrote:
>>Is there something in an errorlog (if that is turned on in php.ini)?


all errors are usually logged in a file as well... Nothing in there.

This is the script how I use the class :
=======
<pre>
<?php
require "nessi.class.php";
$xml = new Nessi;
$xml = loadfile(invoice.xml);
print_r($GLOBALS);
?>
</pre>
=======

The output of the script is :
<pre>
I really haven't got a clue ...
This generally means you have an error in the required file
(nessi.class.php).

Ensure you have all errors enabled and displayed, or check your error
log (often times the server error log) for errors.

I suspect you'll find an error in the class file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 18 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Nisha_tm | last post: by
reply views Thread by Klaus Boehmer | last post: by
2 posts views Thread by Brad Shinoda | last post: by
2 posts views Thread by Terry Richards | last post: by
reply views Thread by Google Mike | last post: by
reply views Thread by FrankL | last post: by
3 posts views Thread by danish | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.