You are here: Re: Test for the existence of a null property « PHP Programming Language « IT news, forums, messages
Re: Test for the existence of a null property

Posted by wildernesscat on 08/08/06 12:07

Hi Jerry,

I'm trying to write a function that checks whether a given object is of
a known class (named 'A' in this example). I want it to work even if
the object has been constructed manually, starting from 'new
StdClass()'.

Danny


Jerry Stuckle wrote:
> wildernesscat@gmail.com wrote:
> > Hello there,
> >
> > I'm looking for a method to test, whether an object has a certain
> > property.
> > Consider the following snippet:
> >
> > class A { var $aaa; }
> > $var = new A;
> >
> > (Assuming that the structure of class A is unknown) I need a way to
> > check whether $var->aaa exists (test positive), and whether $var->xxx
> > exists (test negative). I tried boolean tests, isset(), is_null(), but
> > they can't tell the difference.
> > I guess I could convert the object to an array and test its indices,
> > but that wouldn't be practical for large object with many fields.
> >
> > Any other ideas?
> >
> > Thanks in advance,
> > Danny
> >
>
> Danny,
>
> Once of the concepts of OO programming is encapsulation (not fully
> implemented in PHP), in which can't access $aaa. Anything outside of
> the class should not have access to the internal variables of the class;
> nor should they concern themselves with the internals of the class.
> This limits the effects of changes to the class.
>
> Exactly what problem are you trying to resolve?
>
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация