4

I have a parent class:

class parent{
   var $a = 'param1';
   var $b = 'param2';
   public summary(){
      if($this->a<0 || $this->b<0)
         return FALSE;
      return $this->a+$this->b;
   }
   public set_null(){
      $this->a = null;
      $this->a = null;
   }
}

I need to prevent the summary method from overriding in child class, maybe my team doesn't know if summary method exists before.

class child extends parent{
   public summary(){
      return $this->a+$this->b;
   }
   public set_null(){
      $this->a = 0;
      $this->b = 0;
   }
}

Can anyone help me with this problem?

nicolascolman
  • 549
  • 4
  • 15
kreamik
  • 609
  • 2
  • 11
  • 24
  • 1
    Why are you still using `var` keywords? PHP5 was released in 2004th and gave us `public`, `protected` and `private`. Or have you been learning programming from some outdated crap like CakePHP/CodeIgniter? – tereško Oct 18 '13 at 02:41
  • is current CodeIgniter still a crap? – kreamik Oct 18 '13 at 02:46
  • It's still passing objects around by reference, it's still using global state everywhere, it's still trying to redefine MVC instead of admitting to be completely unrelated to it and it's still ignoring ever principle, practice and law of OOP ... yeah, it is still crap – tereško Oct 18 '13 at 02:50
  • so what is the different between CI and the best OOP framework? i mean what is the deficiency in CI? what if we said CI has another PHP pattern instead of OOP that may be can be developed for future purpose? is it still a crap? – kreamik Oct 18 '13 at 03:06

1 Answers1

15

You can do it using final modifier before summary() method definition in your parent class.

Milosz
  • 511
  • 4
  • 5