Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Rekurencja w klasie
-greg712-
post
Post #1





Goście







Witam serdecznie,
Mam problem z ukończeniem pewnego ćwiczenia, opierającego się na wyliczeniu silni rekurencyjnie, poniżej kawałek kodu:

  1. private function SilniaR(){
  2. return $this->SilniaR($this->argument - 1) * $this->argument;
  3. }


Przy próbie otwarcia tego ćwiczenia, wyrzuca mi:
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 261904 bytes) in C:\xampp\htdocs\learning\zad1.php on line 18

Linia 18 to akurat ten return. Prośba o pomoc (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
-greg712-
post
Post #2





Goście







Generalnie aby przybliżyć co nieco:

  1. class Silnia
  2. {
  3. private $argument;
  4.  
  5.  
  6. private function SilniaR(){
  7. if ($this->argument< 2)
  8. {
  9. return 1;
  10. }
  11. else
  12. {
  13. $licz = $this->argument * $this->SilniaR($this->argument -1);
  14. return $licz;
  15. }
  16. }
  17. }


Niechcę jej dawać "nowego" argumentu, tylko wskazać jej ten prywatny, jak to zrobić?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.09.2025 - 03:53