title: Check if variable been initialized in PHP
body: <p>I have been implementing a Wordpress plugin and I faced a problem with finding out if a variable has been declared or not.</p>
  <p>Let's say I have a model named <code>Hello</code>; this model has 2 variables as <code>hello_id</code> and <code>hello_name</code>.</p>
  <p>In the database we have table named <code>hello</code> with 3 columns as <code>hello_id</code>, <code>hello_name</code> , <code>hello_status</code>.</p>
  <p>I would like to check if a variable has been declared and, if it has, set a value.</p>
  <pre><code>abstract class MasterModel {
      protected function setModelData($data)
      {
          foreach($data as $key=&gt;$value){
              if(isset($this-&gt;{$key})){ // need to check if such class variable declared
                  $this-&gt;{$key} = $value;
              }
          }
      }
  }
  
  class Hello extends MasterModel{
      public $hello_id;
      public $hello_name;
      function __construct($hello_id = null)
      {
          if ($hello_id != null){
              $this-&gt;hello_id = $hello_id;
              $result = $wpdb-&gt;get_row(
                  &quot;SELECT * FROM hello WHERE hello_id = $hello_id&quot;
              , ARRAY_A);
              $this-&gt;setModelData($data);
         } 
      }
  }
  </code></pre>
  <p>The main reason why I am doing this is to make my code expandable in the future. For example I might not use some fields from the database but in future I might need them.</p>