SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot kemp's Avatar
    Join Date
    Aug 2004
    Location
    Campinas
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing parent methods - Why isn't it working?

    I have something like

    PHP Code:
    <?
     
     // parent class
     class A {
         function A($var1,$var2) {
            $this->var1 = $var1;
            $this->var2 = $var2;
         }
         ...
         ...
     
         function var1() {
             return $this->var1;
         }
     }
     
     
     // child class
     class B extends A {
         function B($var3) {
             $this->var3 = $var3;
         }
         
         // function that is supposed to use the var1 value, but it doesn't
         function Test {
             $var4 = 'stringhere' . $this->var1();
         }
     }
    Well, as I said above, the function Test doesn't get the value that I want, though PHP makes no complaints about call to undefined function or something like that. But $var4 can't get the data from var1.

    Any thoughts?

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class extends {
      function 
    ($var1$var2$var3) {
        
    $this->var4 $var3;
        
    $this->A($var1$var2);
      }
      ...

    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •