Re: [PHP] object reflection in php?

2002-03-18 Thread Michael Kimsal

John Coggeshall wrote:
> Why are you going through all of this trouble, exactly?
> 
> If you are looking to store the instance of the object in the databaes,
> why not just use serialize()/unserialize()?? 
> 
> John
> 
> 


If you're trying to map each object property to a specific table column 
in a database, serializing wouldn't help.




Michael Kimsal
http://www.phphelpdesk.com
Taking the ? out of http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] object reflection in php?

2002-03-18 Thread Coggeshall, John


Why are you going through all of this trouble, exactly?

If you are looking to store the instance of the object in the databaes,
why not just use serialize()/unserialize()?? 

John




-Original Message-
From: Erik Price [mailto:[EMAIL PROTECTED]] 
Sent: Monday, March 18, 2002 10:43 AM
To: Filippo Veneri
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] object reflection in php?



On Monday, March 18, 2002, at 06:28  AM, Filippo Veneri wrote:

> Just to make myself understood:
>
> class obj {
>   var $field;
>   function obj( $value ) {
> $this->field = $value;
>   }
> }
>
> $o = new obj( "field value" );
>
> How can i know, if possible,  that the instance of
> obj pointed to by $o has a field named "field"?
>
> This would be useful to write an object to a database
> without knowing its structure 'a-priori'.

Couldn't you just add another method called "return_field_name()" to the

class?  Then you could run this method from the script and you will be 
given the value of the field name.  Your code would look like this:

class obj
{
   var $field;

   function obj($value)
   {
 $this->field = $value;
   }

   function return_field_name()
   {
 return $this->field;
   }
}

then in your code you would do something like:
return_field_name();
?>

This might not work, I don't know much about OO.


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] object reflection in php?

2002-03-18 Thread Michael Kimsal

Erik Price wrote:
> 
> On Monday, March 18, 2002, at 06:28  AM, Filippo Veneri wrote:
> 
>> Just to make myself understood:
>>
>> class obj {
>>   var $field;
>>   function obj( $value ) {
>> $this->field = $value;
>>   }
>> }
>>
>> $o = new obj( "field value" );
>>
>> How can i know, if possible,  that the instance of
>> obj pointed to by $o has a field named "field"?
>>
>> This would be useful to write an object to a database
>> without knowing its structure 'a-priori'.
> 
> 
> Couldn't you just add another method called "return_field_name()" to the 
> class?  Then you could run this method from the script and you will be 
> given the value of the field name.  Your code would look like this:



I think you missed his point.  With your example, you still need
to know the field name, which is what he's trying to avoid.


Filippo, I think what you're looking for is:
get_object_vars
more info at
http://www.php.net/manual/en/function.get-object-vars.php

Does that help?


Michael Kimsal
http://www.phphelpdesk.com
Taking the ? out of http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] object reflection in php?

2002-03-18 Thread Erik Price


On Monday, March 18, 2002, at 06:28  AM, Filippo Veneri wrote:

> Just to make myself understood:
>
> class obj {
>   var $field;
>   function obj( $value ) {
> $this->field = $value;
>   }
> }
>
> $o = new obj( "field value" );
>
> How can i know, if possible,  that the instance of
> obj pointed to by $o has a field named "field"?
>
> This would be useful to write an object to a database
> without knowing its structure 'a-priori'.

Couldn't you just add another method called "return_field_name()" to the 
class?  Then you could run this method from the script and you will be 
given the value of the field name.  Your code would look like this:

class obj
{
   var $field;

   function obj($value)
   {
 $this->field = $value;
   }

   function return_field_name()
   {
 return $this->field;
   }
}

then in your code you would do something like:
return_field_name();
?>

This might not work, I don't know much about OO.


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] object reflection in php?

2002-03-18 Thread Andrey Hristov

get_object_vars(),
get_class_vars(),
get_class_methods()


Andrey

- Original Message - 
From: "Filippo Veneri" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 18, 2002 1:28 PM
Subject: [PHP] object reflection in php?


> Is there a way to get the name of a filed
> from a variable pointing to some object?
> 
> Just to make myself understood:
> 
> class obj {
>var $field;
>function obj( $value ) {
>  $this->field = $value;
>}
> }
> 
> $o = new obj( "field value" );
> 
> How can i know, if possible,  that the instance of
> obj pointed to by $o has a field named "field"?
> 
> This would be useful to write an object to a database
> without knowing its structure 'a-priori'.
> 
> Thanks
> 
> fbv
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php