Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13825 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46856 invoked by uid 1010); 11 Nov 2004 19:33:08 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 46549 invoked from network); 11 Nov 2004 19:33:05 -0000 Received: from unknown (HELO luke.segpub.com.au) (64.49.254.53) by pb1.pair.com with SMTP; 11 Nov 2004 19:33:05 -0000 Received: (qmail 17311 invoked from network); 11 Nov 2004 19:33:05 -0000 Received: from 64.202.110.58 by luke.segpub.com.au (envelope-from , uid 82) with qmail-scanner-1.23 (clamdscan: 0.75.1. spamassassin: 2.64. Clear:RC:1(64.202.110.58):. Processed in 0.039338 secs); 11 Nov 2004 19:33:05 -0000 Received: from unknown (HELO ?192.168.2.126?) (64.202.110.58) by 0 with SMTP; 11 Nov 2004 19:33:04 -0000 In-Reply-To: <535857716.20041111201733@marcus-boerger.de> References: <5917D4B9-33F5-11D9-8B36-000D932DF2B4@sneer.org> <535857716.20041111201733@marcus-boerger.de> Mime-Version: 1.0 (Apple Message framework v619) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-ID: <806AF67A-3418-11D9-8B36-000D932DF2B4@sneer.org> Content-Transfer-Encoding: 7bit Cc: Marcus Boerger Date: Thu, 11 Nov 2004 13:33:02 -0600 To: internals@lists.php.net X-Mailer: Apple Mail (2.619) Subject: Re: [PHP-DEV] __get() "feature" From: jperkins@sneer.org (Jason Perkins) On Nov 11, 2004, at 1:17 PM, Marcus Boerger wrote: >> >> class sales_order { >> ... > >> public function has_a( $class ) { >> $this->relationships[ $class ] = 'has_a'; >> } > >> public function __get( $class ) { >> if(array_key_exists( $class, $this->relationships )) { >> if( $this->relationships[ $class ] == 'has_a') { >> $this->$class = new $class( $this->id ); >> return; > Change the above line to: > return $this->$class; I'd tried that initially as: public function __get( $class ) { if(array_key_exists( $class, $this->relationships )) { if( $this->relationships[ $class ] == 'has_a') { $this->$class = new $class( $this->id ); return $this->$class; } } } called from: $sales_order = new sales_order( 1 ); $sales_order->has_a( 'customer' ); print $sales_order->customer->address1; results in no output being generated. Using a suggestion of Todd Ruth's: public function __get( $class ) { if(array_key_exists( $class, $this->relationships )) { if( $this->relationships[ $class ] == 'has_a') { $value = $this->$class = new $class( $this->id ); return $value; } } } and then running that same print code from above results in: 123 maple street being generated. Which is the test data that I have for the customer table associated with the sales_order with primary id of 1. Weird, huh? -- Jason N Perkins