Is there a generic Object in PHP?
Is there a generic Object in PHP?
am 16.01.2008 03:14:08 von KDawg44
Hi,
I would like to have a function that takes a generic object and takes
some action on this. Something like,
function AMethod(Object obj) {
DoSomeStufftotheObject;
}
then be able to pass various object types in. Is there a way to do
this in PHP? Do classes automatically inherit from a generic Object
like in Java?
Thanks.
Re: Is there a generic Object in PHP?
am 16.01.2008 03:29:59 von Jerry Stuckle
KDawg44 wrote:
> Hi,
>
> I would like to have a function that takes a generic object and takes
> some action on this. Something like,
>
> function AMethod(Object obj) {
> DoSomeStufftotheObject;
> }
>
> then be able to pass various object types in. Is there a way to do
> this in PHP? Do classes automatically inherit from a generic Object
> like in Java?
>
> Thanks.
>
No, there is no generic object in PHP. However, you don't need to
specify what kind of object is being passed, i.e.
function AMethod($obj) {
will take anything (not just objects). And from there you can figure
out what was passed.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Is there a generic Object in PHP?
am 16.01.2008 03:33:48 von KDawg44
On Jan 15, 9:29 pm, Jerry Stuckle wrote:
> KDawg44 wrote:
> > Hi,
>
> > I would like to have a function that takes a generic object and takes
> > some action on this. Something like,
>
> > function AMethod(Object obj) {
> > DoSomeStufftotheObject;
> > }
>
> > then be able to pass various object types in. Is there a way to do
> > this in PHP? Do classes automatically inherit from a generic Object
> > like in Java?
>
> > Thanks.
>
> No, there is no generic object in PHP. However, you don't need to
> specify what kind of object is being passed, i.e.
>
> function AMethod($obj) {
>
> will take anything (not just objects). And from there you can figure
> out what was passed.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Thank you.... my brain is stuck in JAVA mode and i forgot you do not
have to declare what is being passed in!
Thanks!
Re: Is there a generic Object in PHP?
am 16.01.2008 03:36:41 von Jerry Stuckle
KDawg44 wrote:
> On Jan 15, 9:29 pm, Jerry Stuckle wrote:
>> KDawg44 wrote:
>>> Hi,
>>> I would like to have a function that takes a generic object and takes
>>> some action on this. Something like,
>>> function AMethod(Object obj) {
>>> DoSomeStufftotheObject;
>>> }
>>> then be able to pass various object types in. Is there a way to do
>>> this in PHP? Do classes automatically inherit from a generic Object
>>> like in Java?
>>> Thanks.
>> No, there is no generic object in PHP. However, you don't need to
>> specify what kind of object is being passed, i.e.
>>
>> function AMethod($obj) {
>>
>> will take anything (not just objects). And from there you can figure
>> out what was passed.
>>
>
> Thank you.... my brain is stuck in JAVA mode and i forgot you do not
> have to declare what is being passed in!
>
> Thanks!
>
:-)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Is there a generic Object in PHP?
am 16.01.2008 03:53:42 von Daniel Ennis
KDawg44 wrote:
> On Jan 15, 9:29 pm, Jerry Stuckle wrote:
>> KDawg44 wrote:
>>> Hi,
>>> I would like to have a function that takes a generic object and takes
>>> some action on this. Something like,
>>> function AMethod(Object obj) {
>>> DoSomeStufftotheObject;
>>> }
>>> then be able to pass various object types in. Is there a way to do
>>> this in PHP? Do classes automatically inherit from a generic Object
>>> like in Java?
>>> Thanks.
>> No, there is no generic object in PHP. However, you don't need to
>> specify what kind of object is being passed, i.e.
>>
>> function AMethod($obj) {
>>
>> will take anything (not just objects). And from there you can figure
>> out what was passed.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Thank you.... my brain is stuck in JAVA mode and i forgot you do not
> have to declare what is being passed in!
>
> Thanks!
you can also do if(is_object($var)) to make sure its an object.
--
Daniel Ennis
faNetworks.net - Quality Web Hosting and Ventrilo Services
System Administrator / Web Developer
PHP Developer for 6 years
daniel@fanetworks.net
Re: Is there a generic Object in PHP?
am 16.01.2008 11:11:38 von Micah
try using this a generic object:
$obj =3D new stdClass();
On Jan 15, 6:14=A0pm, KDawg44 wrote:
> Hi,
>
> I would like to have a function that takes a generic object and takes
> some action on this. =A0 Something like,
>
> function AMethod(Object obj) {
> =A0 =A0 =A0 =A0 =A0DoSomeStufftotheObject;
>
> }
>
> then be able to pass various object types in. =A0Is there a way to do
> this in PHP? =A0Do classes automatically inherit from a generic Object
> like in Java?
>
> Thanks.
Re: Is there a generic Object in PHP?
am 16.01.2008 14:56:44 von Rob
On Jan 16, 10:11=A0am, micah wrote:
> try using this a generic object:
>
> $obj =3D new stdClass();
>
> On Jan 15, 6:14=A0pm, KDawg44 wrote:
>
>
>
> > Hi,
>
> > I would like to have a function that takes a generic object and takes
> > some action on this. =A0 Something like,
>
> > function AMethod(Object obj) {
> > =A0 =A0 =A0 =A0 =A0DoSomeStufftotheObject;
>
> > }
>
> > then be able to pass various object types in. =A0Is there a way to do
> > this in PHP? =A0Do classes automatically inherit from a generic Object
> > like in Java?
>
> > Thanks.- Hide quoted text -
>
> - Show quoted text -
Just out of interest, is there any way to see what properties,
methods, constructs, etc the generic stdClass object has? Or maybe
it's documented somewhere?
Rob.
Re: Is there a generic Object in PHP?
am 17.01.2008 18:44:25 von luiheidsgoeroe
On Wed, 16 Jan 2008 14:56:44 +0100, Rob wrote:
> On Jan 16, 10:11 am, micah wrote:
>> try using this a generic object:
>>
>> $obj = new stdClass();
>>
>> On Jan 15, 6:14 pm, KDawg44 wrote:
>>
>>
>>
>> > Hi,
>>
>> > I would like to have a function that takes a generic object and takes
>> > some action on this. Something like,
>>
>> > function AMethod(Object obj) {
>> > DoSomeStufftotheObject;
>>
>> > }
>>
>> > then be able to pass various object types in. Is there a way to do
>> > this in PHP? Do classes automatically inherit from a generic Object
>> > like in Java?
>>
>> > Thanks.- Hide quoted text -
>>
>> - Show quoted text -
>
> Just out of interest, is there any way to see what properties,
> methods, constructs, etc the generic stdClass object has? Or maybe
> it's documented somewhere?
Reflection could tell you, but the answer is much quicker: is has none (no
methods, no properties). This also is NOT the 'main class/object' from
which all other classes/objects are derived. It's just an empty container.
--
Rik Wasmus