Skip to content

nielsoffice/PHPClassTypeHintBaseOnParentClass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

PHPClassTypeHintBaseOnParentClass

Class type hint base on parent class as data type

<?php 

interface Only {
  
  public function print_result( string $test ) : string ;
    
}

interface OnlyFor {
  
  public function calculate_result( string $test ) : string ;
      
}

class ParentRequest implements OnlyFor {
   
  public function calculate_result( string $test ) : string
  {
      return (string) $test;
  }

  protected function onlyHere() 
  {
     // 
  }

}

class Child extends ParentRequest implements Only, OnlyFor {
    
    /**
     * Class constructor.
     */
    public function __construct(ParentRequest|Only $data = null)
    {
        
    }
    public function print_result(string $test) : string
    {
        return (string) $test;
    }

} 

About

Class type hint base on parent class as data type

Topics

Resources

Stars

Watchers

Forks