Earlier quoted context omitted.
I was talking more about the inconsistency between return type void when it returns null. I'm asking whether this behavior has changed and functions without a return will now return void or ???. It's a pretty big inconsistency IMHO.
This is the same as other languages. In for example Java you have `public void method()`, and you then `return` which results in a `null`
Upcoming changes in PHP 7.1
51–60 of 137 posts
Re: Upcoming changes in PHP 7.1
#52Re: Upcoming changes in PHP 7.1
#53Earlier quoted context omitted.
Self-documenting code. I'm already using return types wherever I can, and it's nice to keep things consistent. Also, it helps prevent the abuse of interfaces. I can say "this method does not return values" and enforce it. That can be useful on a big project, with junior devs.
I was talking more about the inconsistency between return type void when it returns null. I'm asking whether this behavior has changed and functions without a return will now return void or ???. It's a pretty big inconsistency IMHO.
PHP's built-in functions documented as "void" also return NULL, so I suppose there's an argument from consistency.
Re: Upcoming changes in PHP 7.1
#54Earlier quoted context omitted.
Self-documenting code. I'm already using return types wherever I can, and it's nice to keep things consistent. Also, it helps prevent the abuse of interfaces. I can say "this method does not return values" and enforce it. That can be useful on a big project, with junior devs.
I was talking more about the inconsistency between return type void when it returns null. I'm asking whether this behavior has changed and functions without a return will now return void or ???. It's a pretty big inconsistency IMHO.
There's a lot of code that uses "return;" to mean "return null;" and honestly I don't see it as a big problem.
Re: Upcoming changes in PHP 7.1
#55Earlier quoted context omitted.
My favorite feature is definitely the square bracket destructuring syntax. This is great for bringing tuple-esque operations to the language.
It doesn't bring tuple-esque operations to the language; it's a shorter alternate syntax for the already existing "list()" destructuring syntax.
Re: Upcoming changes in PHP 7.1
#56... Note the syntax isn’t the usual double pipe || operator that we associate with or, rather a single pipe | character ... ... PHP 7.1 introduces visibility modifiers to constants ... ... With PHP 7.1 it is now possible to specify that a function has a void return type, i.e. it performs an action but does not return anything ... ... Example four contains numeric values, so everything else is stripped out, and the su…
I don't like PHP either, but that doesn't mean kneejerk reactions are excusable, and at the least on the first point you are wrong. Using | instead of || is not an inconsistency, but actually quite consistent. || is a short-cutting or comparison operator which returns the first true thing it encounters. | is a bitwise or combinator, which takes two sets of flags, and combines them into one set of flags that has all f…
Re: Upcoming changes in PHP 7.1
#57Earlier quoted context omitted.
But these checks could also be performed by a code analyzer/compiler, removing this burden from the runtime. (Performing the checks at runtime, means the code is only checked when it is executed, which could be at any random time.)
Ahead-of-time type checking can only really work if the entire program has type declarations everywhere, and if you know what constitutes the entire program. This isn't the case for the vast majority of existing PHP code. Furthermore, PHP's dynamic features mean that there are cases where ahead-of-time checks will always be impossible. So you have to have at least some runtime checks, at the boundaries between typed…
Re: Upcoming changes in PHP 7.1
#58Earlier quoted context omitted.
If you're using type signatures, the alternative is probably going to be that your program crashes at a later time. "Foo is not a Bar" is a better error message than "$foo->xyz() isn't a function", and this happens much closer to the point where you've messed up.
I disagree. I think that this type of "late type binding" is actually an advantage of dynamically typed languages. That way it does not matter if you pass a map/array/dictionary or an instance of a class as long as the properties are the same.
Re: Upcoming changes in PHP 7.1
#59Re: Upcoming changes in PHP 7.1
#60... Note the syntax isn’t the usual double pipe || operator that we associate with or, rather a single pipe | character ... ... PHP 7.1 introduces visibility modifiers to constants ... ... With PHP 7.1 it is now possible to specify that a function has a void return type, i.e. it performs an action but does not return anything ... ... Example four contains numeric values, so everything else is stripped out, and the su…
I don't like PHP either, but that doesn't mean kneejerk reactions are excusable, and at the least on the first point you are wrong. Using | instead of || is not an inconsistency, but actually quite consistent. || is a short-cutting or comparison operator which returns the first true thing it encounters. | is a bitwise or combinator, which takes two sets of flags, and combines them into one set of flags that has all f…
I wish. The fact that it actually doesn't is one of the things that really bugs me about PHP:
The above example will output: bool(true)