php -> classes problem

Reply

Join Date: Nov 2008
Posts: 5
Reputation: asciid is an unknown quantity at this point 
Solved Threads: 0
asciid asciid is offline Offline
Newbie Poster

php -> classes problem

 
0
  #1
Nov 21st, 2008
hi guys. i am writing a class for registering data and i am having a problem calling functions and vars from other classes.

here's a class diagram of where everything is called-

http://img376.imageshack.us/img376/19/classesdm8.png


i am in forms, and i am having difficulty getting vars from site, using my functions in postgredb and vars from user.

i can get data from form easily.
  1. $this->var

but when i try getting data from site i get an fatal saying site is not a member of form, ($this->site->var) so, how do i call data from a parent class?


solved
solved it- used a public $p; then set $form->p = $this, and then when calling parent date - $this->p->var...
Last edited by asciid; Nov 21st, 2008 at 3:31 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: php -> classes problem

 
0
  #2
Nov 21st, 2008
you can send a reference to the parent class through the constructor and set it as a local var in the class.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: php -> classes problem

 
0
  #3
Nov 21st, 2008
example:

  1. class test {
  2. var $var;
  3. function __construct() {
  4. $this->var = 'something';
  5. }
  6. function testing() {
  7. echo 'This is the parent function';
  8. }
  9. }
  10.  
  11. class test2 {
  12. var par;
  13. var var2;
  14. function __construct( &$par ) {
  15. $this->par = $par;
  16. }
  17. }
  18.  
  19. $test = new test();
  20. $test2 = new test2( $test );
  21.  
  22. $test2->par->testing() //will echo 'this is the parent class';

thats one way to do it. there are more.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: php -> classes problem

 
0
  #4
Nov 21st, 2008
if the thread is solved, please mark it as so. This way I don't waste anymore time replying to something that you already figured out.
Last edited by kkeith29; Nov 21st, 2008 at 4:40 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC