Earlier quoted context omitted.
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…
> || is a short-cutting or comparison operator which returns the first true thing it encounters. 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)
Upcoming changes in PHP 7.1
61–70 of 137 posts
Re: Upcoming changes in PHP 7.1
#62Earlier quoted context omitted.
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…
> || is a short-cutting or comparison operator which returns the first true thing it encounters. 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)
$ php -r 'var_dump(0 || 42);'
bool(true)
$ php -r 'var_dump(0 ?: 42);'
int(42)Re: Upcoming changes in PHP 7.1
#63Earlier quoted context omitted.
> || is a short-cutting or comparison operator which returns the first true thing it encounters. 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)
PHP does have the shorthand ternary operator `?:`, though, which does what you want here: $ php -r 'var_dump(0 || 42);' bool(true) $ php -r 'var_dump(0 ?: 42);' int(42)
edit: Just to clarify for anyone else unfamiliar with it:
$ php -r 'var_dump(42 ?: 0);'
int(42)Re: Upcoming changes in PHP 7.1
#64I'm more excited by some features not detailed in the article. Return type declarations, which were introduced in PHP 7.0, are being enhanced somewhat. First, it's now possible to declare nullable return types (previously all return types did not permit null): public function getFoo(): ?int; (You can also use ? on parameter and property types.) Second, we now have a void return type for functions where there is no us…
Thank you for getting these added to the language, I think it's a fantastic improvement.
Re: Upcoming changes in PHP 7.1
#65... 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
#66Earlier quoted context omitted.
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…
I've seen quite a few JavaScript bugs and potential bugs exposed after adding incomplete type annotations in TypeScript, so I really don't think it's all or nothing, at least not as a general rule. I've been away from PHP too long to speculate how much it would help here.
Re: Upcoming changes in PHP 7.1
#67Earlier quoted context omitted.
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 didn't understand why the remark was there at all. Honestly | reminds me of sum types and it's the perfect choice here.
I understand the use of pipes for bitwise, but in this case if you read the code in the example, we're basically saying "if the exception is of type A or of type B", personally I'd be inclined to use || if I didn't already know the syntax.
Re: Upcoming changes in PHP 7.1
#68Earlier quoted context omitted.
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…
> || is a short-cutting or comparison operator which returns the first true thing it encounters. 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)
Re: Upcoming changes in PHP 7.1
#69Re: Upcoming changes in PHP 7.1
#70... 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…