Jump to content
php.lv forumi

Objekts objektā


Trac3 !!

Recommended Posts

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 ......

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...