Çift tırnak içinde sınıf dizisi

0 Cevap php

Ben iki sınıf izleyiniz

class A  
{     
    ....  
protected  $arr = array('game_id','pl_id');  
...  
}   
class B extends A   
{  
    //for example here add method   
   private function add_to_DB()    
  {   
      $query = "INSERT INTO TABLE(game_id,player_id)    
                     VALUES(????,????)";   //Here is my question,what I must to write??
mysql_query($query);
}  
}

I try to write ..VALUES(\"$this->arr[game_id]\",\"$this->arr[pl_id]\")", or
VALUES(".$this->arr[game_id].",".$this->arr[pl_id].")" ,but its does not working.

Herhangi bir tavsiye için teşekkürler

I think I found another solution of my question. in my A class I must to have _set and _ get methods.
class A
{
....
protected arr = array('game_id'=>NULL,'pl_id'=>NULL);

    function __set($property, $value)  
 {  
     if (array_key_exists($property, $this->arr)) {  
         $this->arr[$property] = $value;  
     } else {  
         print "Error: Can't write a property other than x & y\n";  
     }
 }


  function __get($property)
  {
      if (array_key_exists($property, $this->arr)) {
           return $this->arr[$property];
      } else {
          print "ERROR: write correct property";
      }
  }

...  
}  

Ve bundan sonra B sınıfı ben takip yazabilirsiniz

private function add_to_DB()
{
$query = "INSERT INTO TABLE(game_id,player_id)
VALUES(\"$this->game_id\",\"$this->pl_id\")"; //Here WAS my question
mysql_query($query);
}

Sizin tavsiye için teşekkürler

0 Cevap