RE: [PHP] object reflection in php?

From: Date: Mon, 18 Mar 2002 16:04:35 +0000
Subject: RE: [PHP] object reflection in php?
Groups: php.general 
Request: Send a blank email to php-general+get-88947@lists.php.net to get a copy of this message
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:pricee@hhbrown.com] Sent: Monday, March 18, 2002 10:43 AM To: Filippo Veneri Cc: php-general@lists.php.net 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: <?php $o = new obj("field value"); print $o->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 pricee@hhbrown.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#88947) next »