Czesc wszystkim!

Borykam sie z problemem juz od paru godzin.
Mianowicie musze skorzystac z niejawnego wywolania metody __toString() w moim obiekcie, aby ten zwrocil mi symbol Newtona.

PHP zwraca mi blad:
Catchable fatal error: Object of class Newton could not be converted to string in /var/www/html/Zadanie_2.php on line 167

Nie mam juz pojecia jak to zrobic, moze ktos cos doradzi?
Nie wiem tez jak wstawic te znaczniki MathML do PHP, szukalem i szukalem tego i ciagle wszystko jest w html/xml.
Gdyby ktos mogl mnie naprowadzic na rozwiazanie problemu bylbym bardzo wdzieczny!

Tak brzmi zadanie:
Uzupelnij definicje klasy Newton o metody, ktorePHP wykorzysta niejawnie podczas konwersji do typu string, ktora pozwoli na przedstawienie symbolu
Newtona w postaci odpowiedniego zestawu znacznikow jezyka MathML.Przyklad symbolu Newtona wygenerowanego w jezyku MathML znajdziesz w pliku MathML.html

Plik MathML.html
CODE
  1. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  2.  
  3. <title>MathML's Newton symbol</title>
  4. </head>
  5.  
  6.  
  7. <p> This is a Newton symbol:</p>
  8.  
  9.  
  10. <math xmlns="http://www.w3.org/1998/Math/MathML">
  11. <mrow>
  12. <mo>(</mo>
  13.  
  14. <mfrac linethickness="0">
  15. <mi>n</mi>
  16. <mrow>
  17. <mi>k</mi>
  18. </mrow>
  19.  
  20. </mfrac>
  21. <mo>)</mo>
  22. </mrow>
  23. </math>
  24.  
  25. </body>
  26. </html>


Plik z silnia:
CODE
  1. <?php
  2.  
  3.  
  4. define("E_NO_INT",0xff000001);
  5. define("E_NEGATIVE",0xff000002);
  6. define("E_TOO_BIG",0xff000003);
  7. define("E_INVALID_CONST",0xff000004);
  8.  
  9. class Silnia
  10. {
  11.  
  12. private static $silniaTab;
  13.  
  14. protected $base;
  15. protected static $object_count = 0;
  16. protected $liczba_arg;
  17. protected $argument;
  18. public function __construct()
  19. {
  20. self::$object_count++;
  21. $this->liczba_arg = func_num_args();
  22.  
  23. if($this->liczba_arg == 0)
  24. {
  25. $this->base = 0;
  26. if(self::$object_count == 1)
  27. self::$silniaTab = array(1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800
  28. ,87178291200,1307674368000,20922789888000);
  29.  
  30. }else if($this->liczba_arg == 1)
  31. {
  32. $this->argument = func_get_arg(0);
  33. if (is_integer($this->argument) && $this->argument >= 0 && $this->argument <= 16) {
  34. $this->base = $this->argument;
  35. if(self::$object_count == 1)
  36. self::$silniaTab = array(1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800
  37. ,87178291200,1307674368000,20922789888000);
  38.  
  39. }else if (is_float($this->argument) && $this->argument >= 0 && $this->argument <= 16) {
  40. return E_NO_INT;
  41. }else if (is_numeric($this->argument) && $this->argument < 0) {
  42. return E_NEGATIVE;
  43. }else if(is_numeric($this->argument) && $this->argument > 16){
  44. return E_TOO_BIG;
  45. }
  46. }else {
  47. return E_INVALID_CONST;
  48. }
  49. }
  50.  
  51. function Calculate()
  52. {
  53.  
  54. if($this->liczba_arg == 0)
  55. {
  56. return self::$silniaTab[$this->base];
  57. }else if($this->liczba_arg == 1)
  58. {
  59.  
  60. if (is_integer($this->argument) && $this->argument >= 0 && $this->argument <= 16)
  61. {
  62.  
  63. return self::$silniaTab[$this->base];
  64.  
  65. }else if (is_float($this->argument) && $this->argument >= 0 && $this->argument <= 16) {
  66. return E_NO_INT;
  67. }else if (is_numeric($this->argument) && $this->argument < 0) {
  68. return E_NEGATIVE;
  69. }else if(is_numeric($this->argument) && $this->argument > 16){
  70. return E_TOO_BIG;
  71. }
  72. }else if($this->liczba_arg > 1){
  73. return E_INVALID_CONST;
  74. }
  75.  
  76. }
  77.  
  78. function __toString()
  79. {
  80. return $this->base . '! = ' . $this->Calculate();
  81. }
  82.  
  83. }
  84. ?>



Plik z symbolem Newtona:
CODE
  1. <?php
  2.  
  3. ini_set('display_errors','1');
  4.  
  5.  
  6. include_once('Silnia.inc');
  7. define("E_INVALID_N_CONST",0xff000005);
  8. class Newton extends Silnia {
  9. protected $n,$k;
  10. private static $silniaTab;
  11. protected static $object_count = 0;
  12.  
  13. function __construct(){
  14. $a = func_get_args();
  15. $i = func_num_args();
  16. if (method_exists($this,$f='__construct'.$i)) {
  17. call_user_func_array(array($this,$f),$a);
  18. }
  19. else
  20. {
  21. throw new Exception("Undefined constructor for given set of arguments",E_INVALID_N_CONST);
  22. }
  23. }
  24.  
  25. function __construct2($in,$ik){
  26. //$this->liczba_arg = 1;
  27. //$this->argument = func_get_args();
  28. //self::$silniaTab = array(1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800
  29. ,87178291200,1307674368000,20922789888000);
  30. $this->n=$in;
  31. $this->k=$ik;
  32. //echo self::$silniaTab[5].' '.$this->n.' '.$this->k;
  33. //$this->Calculate();
  34.  
  35.  
  36. }
  37.  
  38. function Calculate(){
  39.  
  40. //$tmp = $this->argument[1];
  41. //$this->argument = $this->argument[0];
  42. parent::__construct();
  43. $this->base = $this->n;
  44. //echo "base = ".$this->base."<br>";
  45. //$this->argument = $this->n;
  46. //echo "arg = ".$this->argument."<br>";
  47. //echo self::$silniaTab[5]."<br>";
  48.  
  49. $l1 = parent::Calculate();
  50. //echo "l1 = ".$l1."<br>";
  51.  
  52. $this->base = $this->k;
  53. //echo "base = ".$this->base."<br>";
  54. //$this->argument = $this->k;
  55. //echo "arg = ".$this->argument."<br>";
  56. $m1 = parent::Calculate();
  57. //echo "m1 = ".$m1."<br>";
  58.  
  59. $this->base = ($this->n - $this->k);
  60. //echo "base = ".$this->base."<br>";
  61. //$this->argument = $this->base;
  62. //echo "arg = ".$this->argument."<br>";
  63. $m2 = parent::Calculate();
  64. //echo "m2 = ".$m2."<br>";
  65. return $l1/($m1*$m2);
  66. }
  67.  
  68. function __set($name,$value)
  69. {
  70. if ($name == 'n') {
  71. $this->setN($value);
  72. }else if ($name == 'k') {
  73. $this->setK($value);
  74. }
  75. }
  76. function __get($name)
  77. {
  78. if ($name == 'n') {
  79. return $this->getN();
  80. }else if ($name == 'k') {
  81. return $this->getK();
  82. }
  83. }
  84.  
  85. function getN ()
  86. {
  87. return $this->n;
  88. }
  89.  
  90. function getK ()
  91. {
  92. return $this->k;
  93. }
  94.  
  95. function setN ($in)
  96. {
  97. if(!is_int($in)) throw new Exception("no integer value",E_NO_INT);
  98. if($in<0) throw new Exception("negative value",E_NEGATIVE);
  99. if($in>16) throw new Exception("value too big",E_TOO_BIG);
  100. $this->n=$in;
  101. }
  102.  
  103. function setK ($ik)
  104. {
  105. if(!is_int($ik)) throw new Exception("no integer value",E_NO_INT);
  106. if($ik<0) throw new Exception("negative value",E_NEGATIVE);
  107. if($ik>16) throw new Exception("value too big",E_TOO_BIG);
  108. $this->k=$ik;
  109. }
  110.  
  111. }
  112. function __toString()
  113. {
  114. return "nie mam pojecia co tu wstawic";
  115. }
  116.  
  117. $n1=new Newton(5,3);
  118. echo "wynik: " . $n1->Calculate() . "<br>";
  119.  
  120. echo "nasze n to " . $n1->n . "<br>";
  121. echo "nasze k to " . $n1->k . "<br>";
  122. echo "zmieniam n na 7<br> ";
  123. $n1->n=7;
  124. echo "zmieniam k na 4<br> ";
  125. $n1->k=4;
  126. echo "nowa warto��: " . $n1->Calculate() . "<br>";
  127.  
  128. echo "Symbol newtona zapisuje si� tak: $n1 <br>";
  129. echo "A tak dzia�a MathML $n1";
  130.  
  131. ?>