Trac3 !! Posted October 20, 2009 Report Share Posted October 20, 2009 Situācija parādīta šajā koda gabalā, kļūdas paziņojums beigās.. class A{ protected $objects; public function __construct(){ $this->objects = new stdClass; $this->loadClass("B"); } protected function loadClass($className = "", $id = ""){ if(empty($className)){ return $this; } if(empty($id)){ $id = $className; } $className = strtolower($className); $id = strtolower($id); if(isset($this->objects->$id)){ return $this->objects->$id; } $this->objects->$id = new $className; // Kļūda ir šajā rindiņā return $this; } } Kļūdas paziņojums: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in ...... Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted October 20, 2009 Report Share Posted October 20, 2009 aha, ideja sekojosha parbaudi kas ir $className jo man tada sajuta ka tuizsauc klasi kura jau ir izaukta, attiecigi zem katra id tiek izsaukta klase, kura izsauc atkartoti tas pasas klases. Teiksim <?php class klase1 { function klase1() { $this->id++; $this->klase[$this->id] = new klase1(); } } ?> tas ir tas ka es to izprotu. Parbaudi kas ir zem $className Quote Link to comment Share on other sites More sharing options...
Trac3 !! Posted October 20, 2009 Author Report Share Posted October 20, 2009 (edited) if(isset($this->objects->$id)){ return $this->objects->$id; } reku ir tas kas parbauda.. un klasei var but vairakas instances, tur nak pie lietas tas "id" Edited October 20, 2009 by Trac3 !! Quote Link to comment Share on other sites More sharing options...
tas_pats Posted October 20, 2009 Report Share Posted October 20, 2009 nav gadījumā jābūt $this->objects->id ? Quote Link to comment Share on other sites More sharing options...
Trac3 !! Posted October 20, 2009 Author Report Share Posted October 20, 2009 nop :) Quote Link to comment Share on other sites More sharing options...
Trac3 !! Posted October 20, 2009 Author Report Share Posted October 20, 2009 kluda bija taja, ka ieciklojas.. klase B izsauca klases A konstruktoru, kas atkal ieladēja klasi B Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.