-1

This may be a duplicate post, but searching for the answer just led me to the C, Java and ColdFusion ways of doing this...

Given class A with method foo() and class B extends A and also has foo(), I want to run something like:

$b = new B();
$b->A::foo(); (this is working C syntax, but that doesn't seem to work)
tereško
  • 58,060
  • 25
  • 98
  • 150
thatthatisis
  • 783
  • 7
  • 18
  • 3
    parent::foo() from a method within your class B – Mark Baker Feb 20 '13 at 22:10
  • 1
    Thanks, Mark. This occurs to me immediately as well, though modifying our API by adding a method to class B is a last resort. And thank you again 1000 times over for the work on PHPExcel. I can't wait for some features on the way in 1.7.9! – thatthatisis Feb 20 '13 at 22:14
  • +1 for the props on PHPOffice. – BenM Feb 20 '13 at 22:16
  • 1
    @thatthatisis - I'm hoping that 1.7.9 is only a couple of weeks away now; I'm currently testing a major refactoring of the cell structure and some initial changes to the calculation engine (refactoring and a switch from singleton to multiton) in preparation for a major calculation rewrite targeted for 1.8.0 – Mark Baker Feb 20 '13 at 22:23
  • Mark - This is DEFINITELY the wrong place for it, but does that mean that we'll still see some array formula love in 1.7.9? I'm actually in the middle of authoring something for work that translates some of our internal functions into excel formulas for export. It's awesome running into you here! :-) – thatthatisis Feb 20 '13 at 23:40
  • No array formula changes in 1.7.9. This is purely preparatory work because a cell properties need to be structured slightly differently to hold details of array formulae... so I've shaved memory by refactoring some details to the cell cache which I'll then reclaim with the array formula changes; and switching the calc engine to a multiton was an issue anyway – Mark Baker Feb 21 '13 at 08:36

1 Answers1

2

You can't call it directly from the object, you have to call it from within A->foo(), for example:

class A 
{
    function foo() 
    {
        echo "I am A::foo() and provide basic functionality.<br />\n";
    }
}

class B extends A 
{
    function foo() 
    {
        parent::foo();
    }
}

$b = new B;
$b->foo();
BenM
  • 52,573
  • 26
  • 113
  • 168
  • I was afraid this was going to be the answer. If you spot my comment from above, the reason I was asking here was to try to avoid adding a method to class B. I was hoping that this was just something I didn't know about the language as I know it is possible in other languages. – thatthatisis Feb 20 '13 at 22:18
  • Unfortunately not, this is one of the idiosyncrasies of PHP. – BenM Feb 20 '13 at 22:23