Re: referencing objects within objects
| From: | Jesse Swensen | Date: | Sat, 18 Nov 2000 11:31:19 +0000 |
| Subject: | Re: referencing objects within objects | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26038@lists.php.net to get a copy of this message | ||
I think there is one thing you need to change. In the function fieldClass,
just change it to "$this->fetchresult = ...". Now you have a class variable
and you can then do
$field = new fieldClass;
echo $field->fetchresult->blob;
--
Jesse Swensen
swensenj@bellsouth.net
> From: "TSHACK" <TSHACK@SILVER-BAYOU.COM>
> Date: Fri, 17 Nov 2000 05:44:46 -0800
> To: <php-general@lists.php.net>
> Subject: [PHP] referencing objects within objects
>
> I have an object called formCass. Referencing things like $this->sql are no
> problem.
>
> I also have an array, $this->fields, which is an array of fieldClasses
> within formClass.
>
> Within the fieldClass, I do a mysql_fetch_field.
>
> Wait, here's the code:
>
> <?
>
> class fieldClass {
> var $fetchresult;
> var $table_result;
>
> var $input_type; // text, select, radio, hidden
> var $sql; // sql statement for select input_type
> var $title; // display name for field on form
> var $edit_option; // view-only, edit, hidden
> var $validate; // function call to validation procedure.
> var $input_mask; // text of input mask for field.
>
> // Methods definition
>
> function fieldClass ($result, $field_ofs)
>
> $fetchresult = @mysql_fetch_field($result, $field_ofs) or die("Fetch
> Result
> failed");
>
> echo "<PRE>
> blob: $fetchresult->blob
> max_length: $fetchresult->max_length
> multiple_key: $fetchresult->multiple_key
> name: $fetchresult->name
> not_null: $fetchresult->not_null
> numeric: $fetchresult->numeric
> primary_key: $fetchresult->primary_key
> table: $fetchresult->table
> type: $fetchresult->type
> unique_key: $fetchresult->unique_key
> unsigned: $fetchresult->unsigned
> zerofill: $fetchresult->zerofill
> </PRE>";
> }
> } // end of field class definition
> ?>
>
> OK, this works:
>
> blob: $fetchresult->blob
>
> but I want to be able to reference
>
> $fieldClass->fetchresult->blob
>
> or even
>
> $this->fetchresult->blob
>
>
>
> So that the contents will be viewable up at the formClass level (I'm really
> new to all of this, so I've probably shot myself in the foot on three levels
> already).
>
> In essense, I want to be able to reference the contents of $fetchresult
> array as a property of the formClass. I'm assuming that if its just a
> function variable, it will disappear when the function ends.
>
> What is the referencing structure when going down into classes within
> classes like this? Is there another route I should be pursuing?
>
> Yes, I've read through the manual, but the places I thought of to look don't
> cover this. I probably haven't looking in the right place. Just a pointer
> to the proper subject matter will be helpful.
>
> What I have started doing is creating functions within the class to return
> these variables, and functions to set them, like gets and sets in VB, but if
> there is a less tedious way to do this, I would appreciate knowing it.
>
> Dwight
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>