php7.0 strict types

General discussion on PHP
Post Reply
sany6014
Posts: 1
Joined: Sun Mar 19, 2017 5:34 pm

php7.0 strict types

Post by sany6014 » 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?

Post Reply