Live data from Hacker News

Things you should know about PHP 7

pages.zend.com

101–110 of 124 posts

Re: Things you should know about PHP 7

#101

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 (?…

[deleted]

Re: Things you should know about PHP 7

#102

Earlier 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.

> 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 ??.

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

#103
post #48

Earlier 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…

ujson breaks the spec btw ;-) We tried doing the same thing but cffi callbacks are slow. We should maybe revisit that (and make callbacks faster, we did get better on that)

Re: Things you should know about PHP 7

#104
post #6
post #4

Earlier 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.

I'd argue it just needs to evolve and improve. For example Azure's Web Sites and to a lesser extent Amazon's S3 do a great job for what they both are, and they're both "shared hosting."

Re: Things you should know about PHP 7

#105

Earlier 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.

Only null will return the default value. http://3v4l.org/jphnq

Re: Things you should know about PHP 7

#106

Being 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 :)

I know that pain

Re: Things you should know about PHP 7

#107
post #100

> Return Type Declarations & Scalar Type Hints Finally, this took them a long freaking time.

Disclaimer: I use the word "type" in the following to refer to types, tags and classes, because I'm feeling lazy ;)

> 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

#108
post #24

Earlier 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…

I've been having all my clients sign up for a Mandrill account for sending email since it's so unbelievably cheap (usually free) and it completely fixes the email problem.

Re: Things you should know about PHP 7

#109

There are credentials for the HTTP Auth on a staging environment commented out in the source of this webpage (Line 317).

Email Zend.

I looked around and couldn't find an appropriate e-mail address anywhere. If you have one, feel free to let them know.

Re: Things you should know about PHP 7

#110
post #24

Earlier 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…

FWIW I've been seeing an increase of spam from DigitalOcean networks recently -- over the last couple of months or so -- and that's probably going to bleed over into the RBLs and other countermeasure systems that larger mail services use.
Post reply on HN