Void as return type

后端 未结 5 841
忘了有多久
忘了有多久 2020-12-05 13:11

I was testing return types with PHP 7.

I\'ve created a simple script to test return types of PHP 7:



        
5条回答
  •  悲&欢浪女
    2020-12-05 13:36

    @BeNice I understand your point, anyhow I summarize the consideration from Levi Morrison as a practical question of sustainability: introducing void as a possible return type infact, we break the assumption that the only possible type of null is null.

    This way, void should be returned for the type check of null, changing architecture constraints by design and causing a mess in backward compatibility.

    // your choice implies this comparison should be true:
    gettype(null) === void;
    

    I think who used null not frequently in his code would bear the void type implementation.

提交回复
热议问题