Note this is just Zend's take on what's important in PHP 7: it's not a complete list. A more comprehensive list: - Dual-mode scalar type hints (weak by default, toggleable to strict via a per-file syntax) ( https://wiki.php.net/rfc/scalar_type_hints_v5 ) - Return type declarations ( https://wiki.php.net/rfc/return_types ) - operator ( https://wiki.php.net/rfc/combined-comparison-operator ) - Null coalesce operator (?…
Things you should know about PHP 7
101–110 of 124 posts
Re: Things you should know about PHP 7
#102Earlier quoted context omitted.
I feel like I've needed that since I first started coding PHP 17 years ago!
I feel like I want to test what happens if you put values like "", false, " ", 0, an empty array, etc etc etc in front of ??. Because, you know, this is PHP.
All of those would result in the variable being assigned those values: the null check uses the same semantics as is_null(), and the truth table for those values is:
$v is_null($v)
------------------
'' FALSE
false FALSE
' ' FALSE
0 FALSE
[] FALSE
If you want to all falsy values to use the fallback value, use the shorthand ternary operator (?:) instead.Re: Things you should know about PHP 7
#103Earlier quoted context omitted.
json parser on pypy is competitive, try it (or give us examples where it's not). msgpack needs a better impl, but can be done, database drivers seem to work over cffi at reasonable speed.
I just checked out and seems like pypy has made some good progress database driver wise! So I went ahead and installed pypy 2.5.1 to compare the json performance. It got better but ujson is just crazy fast. CPython (w/ ujson) is 70% faster to loads and 50% faster to dumps a sample json from my project (50~156kb json). I expect msgpack to be the same. Unfortunately seems like Pypy still doesn't pay off in this app, bu…
Re: Things you should know about PHP 7
#104Earlier quoted context omitted.
> 1. Scheduled to come out in Q4 2015 ... and available on general cheap webhosting sometime around 2020. If we're lucky. Thank god our company slowly moved away from building small PHP websites that have to run on the most fucked up PHP installations from the before-time. Now it's PHP 5.6+ everywhere :-)
>... and available on general cheap webhosting sometime around 2020. If we're lucky. Shared Hosting needs to die off anyway.
Re: Things you should know about PHP 7
#105Earlier quoted context omitted.
I feel like I've needed that since I first started coding PHP 17 years ago!
I feel like I want to test what happens if you put values like "", false, " ", 0, an empty array, etc etc etc in front of ??. Because, you know, this is PHP.
Re: Things you should know about PHP 7
#106Being a PHP dev since the early 00's it's great to see the language moving forward with features and performance and seemingly less hate towards it from the developer community at large. For a while there seemed to be a "PHP-shaming" thing going around. If you did PHP you were sort of in an untouchable uncool class.
Meh...PHP devs think they've got bad here? I still have to knock out Classic ASP now and again. My dad found out and won't even look at me or answer the phone :)
Re: Things you should know about PHP 7
#107> Return Type Declarations & Scalar Type Hints Finally, this took them a long freaking time.
> Return Type Declarations & Scalar Type Hints
This seems a shame.
We can only add type hints to arguments and return types if we're writing arguments and return values, which is unnecessarily verbose. We should really add these types to the functions themselves. For example:
$dbl = function(int $x) : int { return 2 * $x; };
$neg = function(int $x) : int { return -1 * $x; };
We've given types to the inputs and outputs, but the functions themselves still just have the type 'Closure'; there's no indication about what they accept or return. Functions are meant to abstract, but this implementation of type hinting forces us to go and read the implementation!For example, if we've written the following and we want to add types (where I've put "???"), we need to look at the implementations of $dbl and $neg:
$dblneg = function(??? $x) : ??? { return $dbl($neg($x)); };
We could implement the same functions in a different way: $mult = function(int $x) : Closure {
return function(int $y) : int use ($x) {
return $x * $y;
};
};
$dbl = $mult(2);
$neg = $mult(-1);
Now if we want to add types to $dblneg, the implementations of $dbl and $neg don't help; we have to dig even further and read the implementation of $mult.All of this would go away if we could hint the function instead, eg.
$mult = function($x) : Closure(int, Closure(int, int)) {
return function($y) use ($x) : Closure(int, int) {
return $x + $y;
};
};
$dbl = $mult(2);
$neg = $mult(-1);
Here I've used the ": ???" syntax to hint the whole function rather than just its return value, and I've written "Closure(x, y)" to mean a function type from argument type "x" to return type "y". This means if we have a function, like $dbl, we can query its type in the usual way (`typeof $dbl`) and get the argument and return types without having to read any source.Note that this doesn't require generics/parametric-polymorphism, since all of the types I've used are concrete. However, adding that would be the next logical step ;)
Note that we can trivially extend this scheme to functions with multiple arguments, in all of the various, incompatible ways PHP lets us define them:
function add($x, $y) : Closure(int, int, int) {
return $x + $y;
}
$add = function($x, $y) : Closure(int, int, int) {
return $x + $y;
};
static function add($x, $y) : Closure(int, int, int) {
return $x + $y;
}
public function add($y) : Closure(int, int, int) {
$this + $y;
}
function add($x) : Closure(int, Closure(int, int)) {
return function($y) use ($x) : Closure(int, int) {
return $x + $y;
};
}
function add($args) : Closure(array(int, int), int) {
return $args[0] + $args[1];
}
$add = function($args) : Closure(array(int, int), int) {
return $args[0] + $args[1];
}
static function add($x) : Closure(int, Closure(int, int)) {
return function($y) use ($x) : Closure(int, int) {
return $x + $y;
};
}
function add() : Closure(int, int, int) {
return func_get_args()[0] + func_get_args()[1];
}
function add() : Closure(array(int, int), int) {
return func_get_args()[0][0] + func_get_args()[0][1];
}
// and so on
This seems to me like another case of PHP ignoring decades of programming language research and development and instead just "doing it like does it". It's like generators all over again :( (eg. see http://okmij.org/ftp/continuations/generators.html and http://parametricity.net/dropbox/yield.subc.pdf )Re: Things you should know about PHP 7
#108Earlier quoted context omitted.
Okay, sure, instead your new job is to play security and sysadmin for the DigitalOcean containers for all the small local business Wordpress sites for say $10 an hour. Shared Hosting has many downsides, but it still fills an incredibly important niche for businesses for whom a web presence beyond a Facebook page is needed but real managed hosting is completely out of their price range.
Lol, I'm in the middle of doing this - moving from shared hosting to a DO droplet. It is painful. Setting up the server isn't so bad but email is a nightmare. Unfortunately the large email providers are moving to block a lot of smaller servers it seems which might make it harder in the future at present using an SPF seems to get mails through. DO of course have a Wordpress appliance which makes it pretty easy to set…
Re: Things you should know about PHP 7
#109Re: Things you should know about PHP 7
#110Earlier quoted context omitted.
Okay, sure, instead your new job is to play security and sysadmin for the DigitalOcean containers for all the small local business Wordpress sites for say $10 an hour. Shared Hosting has many downsides, but it still fills an incredibly important niche for businesses for whom a web presence beyond a Facebook page is needed but real managed hosting is completely out of their price range.
Lol, I'm in the middle of doing this - moving from shared hosting to a DO droplet. It is painful. Setting up the server isn't so bad but email is a nightmare. Unfortunately the large email providers are moving to block a lot of smaller servers it seems which might make it harder in the future at present using an SPF seems to get mails through. DO of course have a Wordpress appliance which makes it pretty easy to set…