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
Plik z silnia:
CODE
<?php class Silnia { protected $base; protected $liczba_arg; protected $argument; public function __construct() { self::$object_count++; if($this->liczba_arg == 0) { $this->base = 0; if(self::$object_count == 1) ,87178291200,1307674368000,20922789888000); }else if($this->liczba_arg == 1) { $this->base = $this->argument; if(self::$object_count == 1) ,87178291200,1307674368000,20922789888000); return E_NO_INT; return E_NEGATIVE; return E_TOO_BIG; } }else { return E_INVALID_CONST; } } function Calculate() { if($this->liczba_arg == 0) { return self::$silniaTab[$this->base]; }else if($this->liczba_arg == 1) { { return self::$silniaTab[$this->base]; return E_NO_INT; return E_NEGATIVE; return E_TOO_BIG; } }else if($this->liczba_arg > 1){ return E_INVALID_CONST; } } function __toString() { return $this->base . '! = ' . $this->Calculate(); } } ?>
Plik z symbolem Newtona:
CODE
<?php include_once('Silnia.inc'); class Newton extends Silnia { protected $n,$k; function __construct(){ if (method_exists($this,$f='__construct'.$i)) { } else { throw new Exception("Undefined constructor for given set of arguments",E_INVALID_N_CONST); } } function __construct2($in,$ik){ //$this->liczba_arg = 1; //$this->argument = func_get_args(); //self::$silniaTab = array(1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800 ,87178291200,1307674368000,20922789888000); $this->n=$in; $this->k=$ik; //echo self::$silniaTab[5].' '.$this->n.' '.$this->k; //$this->Calculate(); } function Calculate(){ //$tmp = $this->argument[1]; //$this->argument = $this->argument[0]; parent::__construct(); $this->base = $this->n; //echo "base = ".$this->base."<br>"; //$this->argument = $this->n; //echo "arg = ".$this->argument."<br>"; //echo self::$silniaTab[5]."<br>"; $l1 = parent::Calculate(); //echo "l1 = ".$l1."<br>"; $this->base = $this->k; //echo "base = ".$this->base."<br>"; //$this->argument = $this->k; //echo "arg = ".$this->argument."<br>"; $m1 = parent::Calculate(); //echo "m1 = ".$m1."<br>"; $this->base = ($this->n - $this->k); //echo "base = ".$this->base."<br>"; //$this->argument = $this->base; //echo "arg = ".$this->argument."<br>"; $m2 = parent::Calculate(); //echo "m2 = ".$m2."<br>"; return $l1/($m1*$m2); } function __set($name,$value) { if ($name == 'n') { $this->setN($value); }else if ($name == 'k') { $this->setK($value); } } function __get($name) { if ($name == 'n') { return $this->getN(); }else if ($name == 'k') { return $this->getK(); } } function getN () { return $this->n; } function getK () { return $this->k; } function setN ($in) { if($in<0) throw new Exception("negative value",E_NEGATIVE); if($in>16) throw new Exception("value too big",E_TOO_BIG); $this->n=$in; } function setK ($ik) { if($ik<0) throw new Exception("negative value",E_NEGATIVE); if($ik>16) throw new Exception("value too big",E_TOO_BIG); $this->k=$ik; } } function __toString() { return "nie mam pojecia co tu wstawic"; } $n1=new Newton(5,3); $n1->n=7; $n1->k=4; ?>