|  | Posted by GameboyHippo on 10/16/07 14:38 
On Oct 16, 9:11 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:> On 16 Oct, 14:46, GameboyHippo <jasonwthomp...@gmail.com> wrote:
 >
 >
 >
 > > I have a get function that looks like this:
 >
 > >         /**
 > >          * Magic function that gets properties
 > >          * @param mixed $var The property that should be retrieved
 > >          * @return mixed The value of the property.  Returns null if property
 > > doesn't exist
 > >          */
 > >         function __get($var)
 > >         {
 > >                 $special_properties = array('name');
 >
 > >                 if (!isset($this->data[$var]) && !in_array($var,$special_properties))
 > > {
 > >                         echo "Warning: $var is not a property for ".get_class($this)."!\n";
 > >                         return null;
 > >                 }
 > >                 else{
 > >                         switch ($var){
 > >                                 case 'name':
 > >                                         return $this->data['first_name'].' '.$this->data['last_name'];
 > >                                         break;
 > >                                 case 'office_phone':
 > >                                 case 'mobile_phone':
 > >                                 case 'other_phone':
 > >                                         return $this->to_phone_string($this->data[$var]);
 > >                                         break;
 > >                                 default:
 > >                                         return $this->data[$var];
 > >                         }
 > >                 }
 > >         }
 >
 > > Here's the question.  Say I have a row in my database that has a null
 > > value in the column other_phone.  When it gets to the first if
 > > statement !isset($this->data[$var]) it is going to evaluate to true
 > > (in other words $this->data['office_phone'] is not set because it is
 > > null).  How do I evaluate if the column is merely not there instead of
 > > not there or null?
 >
 > If $this->data['office_phone'] is set to NULL then I would expect !
 > isset($this->data[$var]) to evaluate to false, because !isset($this-
 >
 > >data[$var]) IS set.
 
 I agree, however in practice, it doesn't work as expected.  I'll check
 out the other reply and see if that helps.  Thanks!
 [Back to original message] |