Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP4 -> PHP5 issue

Mathieu Maes
Guest
 
Posts: n/a
#1: Aug 17 '06
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 ?


B.r.K.o.N.j.A
Guest
 
Posts: n/a
#2: Aug 17 '06

re: PHP4 -> PHP5 issue


Mathieu Maes wrote:
Quote:
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 ?
>
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
Dikkie Dik
Guest
 
Posts: n/a
#3: Aug 17 '06

re: PHP4 -> PHP5 issue


Is there something in an errorlog (if that is turned on in php.ini)?
Mathieu Maes
Guest
 
Posts: n/a
#4: Aug 17 '06

re: PHP4 -> PHP5 issue



Dikkie Dik wrote:
Quote:
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 ...

Dikkie Dik
Guest
 
Posts: n/a
#5: Aug 17 '06

re: PHP4 -> PHP5 issue


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

Mathieu Maes wrote:
Quote:
Dikkie Dik wrote:
Quote:
>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 ...
>
IchBin
Guest
 
Posts: n/a
#6: Aug 18 '06

re: PHP4 -> PHP5 issue


Dikkie Dik wrote:
Quote:
Does the nessi class code start with <?php ? It may start with <? while
short tags are not configured in php.ini
>
Mathieu Maes wrote:
Quote:
>Dikkie Dik wrote:
Quote:
>>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();
Quote:
Quote:
>$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-)
Mathieu Maes
Guest
 
Posts: n/a
#7: Aug 18 '06

re: PHP4 -> PHP5 issue


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:
Quote:
Dikkie Dik wrote:
Quote:
Does the nessi class code start with <?php ? It may start with <? while
short tags are not configured in php.ini

Mathieu Maes wrote:
Quote:
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();
>
Quote:
Quote:
$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-)
Jerry Stuckle
Guest
 
Posts: n/a
#8: Aug 18 '06

re: PHP4 -> PHP5 issue


Mathieu Maes wrote:
Quote:
Dikkie Dik wrote:
>
Quote:
>>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.
jstucklex@attglobal.net
==================
Closed Thread