How can I prevent the something method below to be created in the foo class ?
class fooBase{
  public function something(){
  }
}
class foo extends fooBase{
  public function __co开发者_如何转开发nstruct(){
    echo $this->something(); // <- should be the parent class method
  }
  public function something(){ 
    // this method should not be allowed to be created
  }
}
Use the final keyword  (like in Java etc):
class fooBase{
  final public function something(){
  }
}
class foo extends fooBase{
  public function __construct(){
    echo $this->something(); // <- should be the parent class method
  }
  public function something(){ 
    // this method should not be allowed to be created
  }
}
See PHP Final keyword. Note that foo will still have a method something, but something will only come from fooBase and foo can't override it.
Use the final keyword.
In your parent:
final public function something()
You can use final to prevent base methods being overwritten.
class fooBase{
  final public function something(){
  }
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论