php7.0 strict types

General discussion on PHP

php7.0 strict types

Postby sany6014 on Mon Mar 20, 2017 9:25 pm

Hi everyone!
Do you agree with behavior in code below:
Code: Select all
declare(strict_types=1);

abstract class Core {
    abstract public function foo(array $arr): int;
}

class A extends Core {
    public function foo(array $arr): string {
        return 'asdas';
    }
}
- this one will thrown Fatal error because of function signature,

but not this -
Code: Select all
declare(strict_types=1);

trait Core {
    abstract public function foo(array $arr): int;
}

class A {
    use Core;
   
    public function foo(array $arr): string {
        return 'asdas';
    }
}


And what do you think about this?
sany6014
 
Posts: 1
Joined: Sun Mar 19, 2017 5:34 pm

Return to PHP

Who is online

Users browsing this forum: No registered users and 1 guest