October 22, 2015

Apply Filters
Apply Filters
Episode 50: PHP7 and What It Means To You
Loading
/

Welcome to Apply Filters, Episode 50.  Today we’re talking about the upcoming launch of PHP7 and what it could mean to you as a WordPress theme and plugin developer.  This update to the framework will bring massive performance improvements, but along with that will come several adjustments to how we handle code, compatibility, and interaction with other plugins.

This show is sponsored by WP Ninjas, makers of Ninja Forms and Ninja Demo.

ninja-forms

Updates:

Pippin

  • New site for Restrict Content Pro with a lot of help from Andrew Munro
  • Rolling out Mailchimp automation, especially with EDD to get people into a drip campaign
  • Initiative to increase happiness scores in HelpScout and overall customer service performance
  • Team Retreat around Pressnomics in March in Phoenix.

Brad

  • Been troubleshooting ads in Adroll
  • OffloadS3 – managing compatibility with popular other plugins via add-on licenses to base plugin
  • MigrateDBPro
    • New UI based on Backbone.js
    • Multisite integration
  • Company retreat – around WordCamp Europe in Vienna, Austria next year.

PHP7:

  • Release date expected to be November 12
  • Performance improvements with PHP7 will be significant (2-3x improvement over PHP5)
  • Exception handling – errors will be caught as exceptions
  • Testing tools are available to forward test your code against the new framework.

To take a look at the documentation around PHP7 check out the Zend blog at www.zend.com/en/resources/php-7.

The Make blog in WordPress has been chronicling the upcoming changes to PHP7 and what it may mean to WordPress theme and plugin developers.  The most recent article from them is at https://make.wordpress.org/core/2015/09/10/wordpress-and-php7/.

If you’re enjoying the show we sure would appreciate a Review in iTunes.  Thanks!

Transcript

INTRO: Welcome to Apply Filters, the podcast all about WordPress development. Now here’s your hosts, Pippin Williamson and Brad Touesnard.

PIPPIN: Welcome back to Episode 50 of Apply Filters. This episode, as usual, is sponsored by the WP Ninjas, the creators of Ninja Forms, Ninja Demos, and a few other great WordPress plugins. You should go check them out at WPNinjas.com.

They’re doing some really cool stuff with their new Ninja Forms 3.0 that they’ve been previewing, so go check it out. Their YouTube channel has some previews of it, if that’s something that you’re interested in. We definitely appreciate all their support. It helps us to put this show together for you guys.

BRAD: For sure. If you are running a little WordCamp and having trouble getting sponsorship, you should reach out to us because we’re looking to help out kind of the smaller WordCamps that are having trouble. If you’re a small WordCamp, yeah, let us know. We can try to help you out.

PIPPIN: Yeah, it’s going to be really fun to try and help some of the smaller ones. In the last few years, I’ve gone to a lot of different WordCamps, and some of the small ones have been some of my favorites. They’re a little more intimate. I like to see people that are just getting a WordCamp started and, yeah, so we’d love to help out in any way that we can.

BRAD: Awesome. What have you been up to, Pippin?

PIPPIN: I’ve been doing a few things. It’s been two and a half, three weeks since our last episode. I know we’re a couple days behind. I was traveling over the weekend and had some things come up during the week last week, so we’re a few days behind.

During that time, we just launched a new website for my Restrict Content Pro plugin. This is my membership plugin that I’ve worked on for the last four and a half to five years.

BRAD: Oh, yeah. I saw that last week. This site looks great.

PIPPIN: Fantastic. I’m glad you like it.

BRAD: Yeah. There’s like little animations here and there that are–

PIPPIN: There are. Yeah. That’s all Andrew Monroe’s work. He’s my partner on Affiliate WP. He’s been working on EDD for the last three years or so. He did the Affiliate WP website. He did my new PippinsPlugins.com site that we launched about eight months ago, and so now he’s done Restrict Content Pro.

BRAD: Yeah, so if you go to that site, make sure when you get to the bottom at the sign-up form, hover over the little dragon mascot, and he flies. He starts to fly.

PIPPIN: Yeah.

BRAD: It’s a nice, little–

PIPPIN: That was one of my favorite little aspects of the site that we kind of put in a little Easter egg. It actually took, I think, three or four days for anyone to notice, or at least anyone to notice it and said anything.

BRAD: Yeah. Yeah, that’s awesome.

PIPPIN: I’m excited to have this site launched finally. The plugin, Restrict Content Pro, has been sold under the PippinsPlugins.com site for the last two and a half years. Before that, it was sold on Code Canyon. It’s never really had its own dedicated home. It’s always had a single page within my main website, and sometimes I think that has caused it to lose a little bit of focus or to not get as much attention as maybe it could have. I’m excited that we have the new site.

We’re going to continue to expand it over the next few months. This was kind of our soft launch. The plugin is actually still purchased on PippinsPlugins.com. This is more like a really extensive landing page. But, eventually everything is going to get moved over as well.

BRAD: Right. It kind of legitimizes it as more of a real product, it seems.

PIPPIN: Right, and that’s one of the big reasons for doing it.

BRAD: Yeah. I mean you have some really great customers using that product, and so it definitely deserves–

PIPPIN: Yeah, there are some very large sites using it.

BRAD: Yeah.

PIPPIN: That’s been one of my goals for the last six months or so was to focus on the plugin a little bit more and to try and really grow it. The plugin has always done really well for me. Ever since it was on Code Canyon, it’s always been one of my staple products. But, after Easy Digital Downloads and Affiliate WP came out, it started to lose a little bit of the focus. It never grew as much as either of those did, and it was kind of my hobby project.

I want to take it and, over the next year, bring it up so that it’s not a hobby project anymore; that it is a full-fledged business on its own. It won’t necessarily have its own legal business entity. It’ll still be under the Pippins Pages brand, but it is a full-fledged project that will hopefully be — yeah, I want to grow it a lot more.

I want to double or triple its size in the next month. Sorry. Not month. A month would be amazing. That’s not going to happen. That would be crushing. But, in the next year, I’d like to really bring it up.

Beyond that, which did take a while, I’ve been doing a bunch of work with MailChimp automation, so I’ve done this in the past, and I’ve written about it a couple of times. We’re doing a lot of automation, especially with Easy Digital Downloads, with sending, getting people into kind of a cycle whenever they purchase specific products for EDD that then follows them up with, whether it’s documentation or things that they can do to go further with a product.

We’ve had some of these in place for a while now for RCP and Affiliate WP and, like, a generic EDD one. Now we’re starting to expand it a lot to go to specific EDD products. If you purchase front-end submissions, which is one of our primary add-ons, you’re going to get a series of emails that are catered specifically to that. With about 100 primary extensions that we manage, that means a lot of different MailChimp campaigns that we’re putting together. We’re trying to go through and do the top 10 or 20 of them.

BRAD: Are those opt-in or are they mandatory if you purchase?

PIPPIN: They’re automatic the moment you purchase.

BRAD: Right. Okay.

PIPPIN: But you can opt out at any time.

BRAD: Right.

PIPPIN: Then two other things that have been my focus for the last week or so, well, this one is new, but we started. At the end of last week, we decided to kind of put together a team challenge and look at our support quality. Not just our support quality, but also our efficiency, how well we’re doing with our happiness ratings, how quickly were we responding, how quickly we’re getting tickets solved, and we kind of made a challenge for ourselves.

We set a goal for a month from today, or a month from the day that we had set this up, to improve various stats by a certain percentage. I’ll run through these really quick just to give you an idea. We wanted to improve.

  • We wanted to decrease the number of replies sent, like the total emails that we send by, say, like 2%.
  • We want to increase the number of tickets that get resolved on the first reply. Right now we’re at about 48%. We want to get it above 50%.
  • We want to get our handle time, an average, like right now we have an average handle time of 5 minutes and 30 seconds. We want to get it down below that. We want to drop it.

BRAD: I could tell you how you could get it really low. You just set up a workflow in Help Scout to send every message to the trash.

PIPPIN: That does in fact work. Unfortunately, that impacts a different part of our goal, which is to improve our happiness scores.

BRAD: Right.

PIPPIN: And so I have a feeling that would probably make them go down.

BRAD: Yeah, yeah, and probably sink your business too.

PIPPIN: Yeah, it might not do very well. We started looking at this, and so we kind of looked at a whole bunch of stats and decided that, every month, we want to set a goal. I’ve always had this maybe unfortunate habit of just kind of assuming things are going really well in support and assuming that we don’t necessarily need to make improvements or maybe there’s not improvements to make. We want to start improving it. Even if it’s great today, we want to make it even better, so we decided to look at all the stats and then set a goal.

Every 30 days, we’re going to reanalyze our stats, and we’re going to set goals. We’re going to see if we can achieve those in various manners, whether that means using more canned replies, just taking longer to answer an initial ticket, or getting more people onboard, whatever it is. Those are our goals, so that was a big focus for the end of last week, and we’ll see how it goes over the next 30 days before we reassess. I’m sure we’ll talk about. Once we kind of figure out, once we see what our stats are on the first review, we’ll talk about it on an episode, I’m sure.

Well, anyway, Brad, how about you? What are you up to?

BRAD: I’ve been working on hiring. Actually, we’re going to hire another full-time developer. I posted on Authentic Jobs, and we got over 100 submissions, so going through those and reviewing code and stuff has just been really time-consuming.

Then I’ve had this problem with AdRoll, the ad platform that we use. It wasn’t serving our ads for, like, two weeks. They changed something on their end, just stopped serving ads, and we had no way of knowing. I logged in one day, and I noticed that the graphs were looking funny, kind of flat. It turns out they weren’t serving our ads.

PIPPIN: Oh, no.

BRAD: Yeah.

PIPPIN: Were they charging you for ads that you weren’t being served?

BRAD: No, at least they weren’t charging us.

PIPPIN: Well, that’s good, at least.

BRAD: Yeah, but we would have figured that out pretty soon when the bills came back and it was like, you know, nothing. It was a little disappointing that it took them so long to fix it. I told them on, like, a Thursday, I think it was, and it didn’t get resolved until, like, Tuesday or Wednesday last week, or something. And so that was a little disappointing and frustrating, but it’s done now, so we’re out of the woods.

I’ve been working with the team on Offload S3, 1.0.2, which is just a bunch of bug fixes and stuff. One interesting decision we’ve made for that is around add-ons. We were previously going to just add compatibility code into the core. Here’s a real example. The plugin is not, by default, compatible with Meta Slider, which is a super popular, free slider plugin on .org. And so we have to add some code to get it to work, some very specific code for that particular plugin to get it to work with our plugin.

We decided to make those add-ons, so to take that code and put them in add-ons, and there are a few reasons for that.

PIPPIN: What is the reasoning for doing that instead of putting it into the core plugin?

BRAD: Yeah, well, the advantage of putting it in the core plugin is it just works, right? No one will ever notice a problem with those, with Meta Slider, for example. That’s a big advantage there. The disadvantage, though, is that all the people that aren’t using Meta Slider, which is a significant portion of people, have that code in there that’s not going to be used, which is not a big deal.

PIPPIN: Right, as long as the code isn’t loaded when it’s not needed, who cares?

BRAD: Yeah, exactly.

PIPPIN: Yeah.

BRAD: But then again, it depends how much code is required to make it compatible, right? If it’s 1,000 lines of code or something, that’s not really great to be distributing that, and that’s just for one plugin compatibility. What if we have two dozen plugins that we need to be compatible with, and we have to add compatibility code? That’s one thing.

The other thing is that it’s not very publicly visible. We could list it somewhere in our documentation that we make it compatible with Meta Slider.

PIPPIN: Sure. Releasing an add-on is kind of that extra visibility, so people searching for Meta Slider find your add-on, and then they say, “Oh, this is cool.”

BRAD: Yes, exactly. And it’s kind of a pledge as well. Because you’re releasing it as an add-on and it’s very public, it’s not like tomorrow you’re going to just say, “Oh, we don’t support that anymore,” right? It’s much more difficult, at least, to do that because that’s what they bought into. They bought into you supporting that add-on, right?

It’s kind of part of the deal, right? It becomes more part of the deal than just kind of a footnote in your documentation. That’s kind of why we tipped–

PIPPIN: Will you be releasing those as free plugins on WordPress.org, or will they be available for paid license key holders only?

BRAD: Paid license only. Some of these compatibilities are extremely time-consuming to deal with.

PIPPIN: Sure. That’s also an upsell for you to get people to upgrade to the paid….

BRAD: Exactly. Exactly, yeah, like some of our licenses will be compatible with a dozen popular plugins, right?

PIPPIN: Right.

BRAD: WPML is another one that we will be supporting as of this service.

PIPPIN: Oh, man, I can imagine that one will be super tough.

BRAD: Yeah.

PIPPIN: Maybe not tough, but extensive.

BRAD: Yeah. They have add-ons for their plugin too, so it’s not just WPML. It’s WPML and their media extension or whatever.

PIPPIN: Right. We had that. We ran into that same topic when building out Affiliate WP for the first time, trying to decide are we going to build each integration, so like the WooCommerce integration, the Easy Digital Downloads integration, the RCP integration, the Member Press integration, etc. Are we going to build each of these as add-on plugins that people download after they’ve purchased the plugin? We actually ended up going with the alternate approach than what you’ve decided, mostly because we decided that we ultimately wanted to have that one, like you install and you’re done, and it just works. But I think both are very valid reasons.

We do run into that still all the time with EDD. EDD is obviously built with the add-on model, which Affiliate WP is not really. We run into the question of: If we need to build a compatibility layer between two systems, between EDD and, say, LearnDash, which is an LMS system, do we build an add-on plugin or do we build it into core? I think our general philosophy came out to be like: If we’re fixing a compatibility bug between the two, like they have a script that loads that breaks us, or we do something that breaks them, make it a core. If we’re adding a feature, then it’s an add-on.

BRAD: Right. That’s a good policy. Yeah.

PIPPIN: I don’t know if it’s always black and white, but I think, maybe as a starting point, that’s worked well.

BRAD: Yeah. Yeah, that’s pretty much the way we look at it too. We do have some, what I would consider, bugs or quirks that we still build into core so that it just works, and they don’t have to install an add-on for it to work. But, generally, those are more wide sweeping ones too. They’re not, generally, specific, like one plugin it affects.

Other things we’ve been working on: Jeff has been working on the Migrate DB Pro 1.6 release, which is going to be a big UI update. He’s working with Backbone for the first time, which is pretty cool. And so our new UI is going to be Backbone powered, which is kind of neat.

PIPPIN: What are the reasons for building a new UI? Is it just to rebuild it, or is it to fix problems?

BRAD: Well, it’s going to be a lot nicer. Our new UI is going to show the progress per table, for example. Our current UI, the progress is just one big bar, but this one you can actually expand and see individual tables progress, as they migrate.

PIPPIN: That’s cool. When you guys are doing the migration, do you go table-by-table, or do you have multiple tables running at the same time?

BRAD: We go table-by-table. We probably could go multiple at a time. But, to be honest, we’ve actually added features to slow down the migrations because of denial of service software thinking that our requests are actually attacks. Yeah, that’s probably a bad idea for most servers.

I guess another thing, like with Migrate DB Pro, the UI update, there’s going to be a settings panel. We kind of rejigged it a bit to clean it up some and stuff like that. There are a few other UI tweaks here and there.

Then the other thing is the multisite tools add-on for Migrate DB Pro. You’re going to be able to push a sub-site into a single site install, and you’re going to be able to pull from a multisite install. You’re going to be able to pull a single site install into it as a sub-site.

PIPPIN: Holy crap! That is so ridiculously cool.

BRAD: Yeah.

PIPPIN: I cannot tell you the number of times that I needed to do that back when I was running, doing client development, because I would build client sites in one multisite install. Then I’d realize that I had to get them out, and that was a pain because I didn’t want to set up a new WordPress install for every single client I had at the time. This was way before Vagrant or any of the new tools that have come up that have made this all a lot easier.

BRAD: Right. We’ve had that question come up from people, actually, like whether they should do that or not, whether they should use a multisite install to do development, so have each client in a separate sub-site. What do you normally say to people that would ask you that?

PIPPIN: I think there’s another question you have to answer first. Are they doing the development of the site or are they also populating the content and doing everything there, because the code on the site is very easy to move around. But, if you have to move a database as well, that’s a whole different story.

BRAD: Right. I’ve always told them that you should always look at where it’s going to end up. If it’s going to end up as a single site somewhere, then you should develop it as a single site because you want your development environment to mirror your staging or production environment as close as possible, right?

PIPPIN: Yeah. I definitely agree with that. But, at the same time, I think there’s a little bit of a caveat. I believe that if you are building a site, it shouldn’t matter if it is multisite or if it is a single site. It should just work regardless. There is no reason that your site that you’ve built in a multisite environment won’t run as a single site. If it does, then maybe you should look at what’s causing that to not work.

I don’t disagree with you that your development environment should as closely mimic the live environment as possible, especially if you’re talking about large-scale client sites. Then there’s no questions asked.

BRAD: Right. Yep. Yeah, I mean that’s the bottom line for me. If you’re developing a theme, I completely agree with you. I think maybe you should use multisite to develop it because then you’re testing in that environment that’s kind of not as typical, maybe, but yeah.

PIPPIN: We use multisite for all my local host development.

BRAD: Yeah.

PIPPIN: Everything runs in multisite. Primarily, I started doing this when we started building Affiliate WP because suddenly I had all of these local setups for all the different e-commerce and membership platforms, as we were integrating with them. I finally decided, wait, this is silly. I’m going to make one multisite install, and every single site in the network will be a different plugin. That way I’m not constantly reconfiguring settings or doing things like that.

BRAD: Right. Yeah, I do the same. I’ve got a multi-sites install to do dev locally just for that reason. Yeah.

Yeah, I guess the only other thing is we’ve decided on our company retreat. We’re going to do it around WordCamp Europe in Vienna next year.

PIPPIN: Oh, very cool.

BRAD: Yeah, that’s pretty exciting, right?

PIPPIN: What’s the date for WordCamp EU?

BRAD: Good question. Is it April, or is it June? Yes, it’s June. It’s the end of June, so I think it’s the 23rd to the 26th or 24th to the 26th, I think.

PIPPIN: Very cool.

BRAD: End of June, yeah.

PIPPIN: Yeah. We’re going to do a team retreat at PressNomics this year.

BRAD: Oh, nice.

PIPPIN: Which will be in April? Is it April or March?

BRAD: March.

PIPPIN: March. That’s right.

BRAD: Yeah, early March. I think March 4th, actually.

PIPPIN: Yeah, so we’re all convening in Phoenix, Arizona.

BRAD: Well, I will see you there because I will also be there.

PIPPIN: Fantastic. I’m looking forward to it.

BRAD: Yeah. Should we go–?

PIPPIN: All right, should we jump into the meat of our episode?

BRAD: Yeah, PHP7.

PIPPIN: All right.

BRAD: Sweet.

PIPPIN: PHP7 is coming along. I’m pretty excited for it.

BRAD: Yeah.

PIPPIN: I think our release date is November 12th.

BRAD: Yeah, the release date.

PIPPIN: Plus or minus a day or two.

BRAD: Yeah. I don’t know if that’s still accurate or not, but I think that’s what they were shooting for recently.

PIPPIN: Yeah. All right, so why do we care about PHP7? We had a little bit of a discussion here in our pre-show about how, as long as you’re not running 5.2, a lot of times we kind of ignore the PHP version that we’re running. Okay, you’re running PHP5.3, 5.4, 5.5, 5.6. All of those are fine, more or less. There are some things that changed between them. But, overall, we’re not as concerned with the exact version that you have now.

Now, PHP7 is a really big deal. Why is PHP7 a really big deal?

BRAD: Performance. Yeah, the tests that I’ve seen, it’s two to three times faster than PHP5.6, and I believe PHP5.6 had some pretty significant improvements over its predecessors as well. PHP7 is clocking in really close to what HHVM gets, which is–

PIPPIN: Can you give us maybe just like a rough ballpark of what kind of performance increase do we see?

BRAD: Well, two to three times faster than 5.6, I think, kind of gives people an idea.

PIPPIN: That’s impressive.

BRAD: Yeah, I mean that’s pretty awesome. I mean that’s huge. That is an incentive to upgrade, right? If you care at all about performance, like how fast your website loads, which most people do.

PIPPIN: Just thinking that simply by upgrading your PHP version–ignore every other aspect of performance on your site–that alone would dramatically affect it. I don’t know about you, but I don’t need a much bigger incentive to upgrade than that.

BRAD: No, I don’t either. If you’re caching your site right now, obviously that’s not going to make a big difference. PHP is kind of out of the mix when you’re talking–

PIPPIN: Right, because if the PHP process isn’t even running, then that performance doesn’t matter.

BRAD: Exactly.

PIPPIN: But any time that you were serving a non-cache request–

BRAD: Non-cache request or the first request, the very first request that is where the cache has expired or has been purged and no longer exists, you’re going to get a lot faster response time from PHP.

PIPPIN: It’ll be a huge deal for anybody who has a largely dynamic site–think e-commerce–where a huge number of the PHP processes, I mean nothing is cashed. Things are cashed, but because there’s so much dynamic data, there are so many non-cache requests going through. That’ll make a huge difference.

BRAD: Right. I guess the other thing is people might be wondering why not just use HHVM. Why do we care about this? But HHVM is not exactly a drop-in replacement for PHP. You have to get your PHP application ready for HHVM.

PIPPIN: Right, because there are some things that don’t work quite right.

BRAD: Yeah. That’s my understanding. I’ve never actually done it. I’ve looked into it a little bit, and it was like, oh, okay, so it’s not. It’s not an exact replacement.

PIPPIN: We’ve done it a few times in EDD only because we have some customers running HHVM. And so, every now and then, we have to look into compatibility issues for them. More or less, things work as is, but there are a few nuances.

BRAD: Yeah. We’ve done some testing with HHVM and Migrate DB Pro. I haven’t done it personally, so I don’t know exactly what’s going on there. But, yeah, Ashley would know.

PIPPIN: All right, so outside of performance, which is a huge improvement, what kind of changes are we looking at? Is there anything that directly impacts developers, things that they might need to do in their applications, or things that they may want to take advantage of?

BRAD: Yeah, so I guess what’s breaking in PHP7.

PIPPIN: That’d be a good place to start, for sure.

BRAD: One of the bigger ones is the way errors are reported. Most errors are reported as an exception now.

PIPPIN: Right. Previously it would be a fatal error.

BRAD: Yeah, a fatal error, a warning, or a notice if you’re in development mode. Now it’s all exceptions. If you don’t have exception handling built in, then it just bubbles up and then becomes like a typical error. Where this becomes a problem, though, is if you do have try/catch blocks in place, but you’re not anticipating or you’re anticipating something bubbling up as just a regular error, not an exception. Then, in PHP7, it becomes an exception. Then that try/catch block executes, right?

PIPPIN: Right. You catch it unexpectedly.

BRAD: Yeah, you start catching errors unexpectedly. Yeah, there’s definitely code that I’ve seen out there that has a lot of try/catch blocks in it that this is going to be a huge problem for them. That’s one thing just to be aware of.

PIPPIN: But it could also be a really nice change for others.

BRAD: Yeah, I think so. I think it’s a great way forward. I don’t really like the idea of having two different, separate kinds of classes of errors or categories of errors. This kind of brings it all together. It seems nice and neat to me.

PIPPIN: Yep. Now, I believe, in PHP7, they are also not only deprecating some things, have actually removed quite a bit of stuff. Do you want to talk briefly about what’s being removed?

BRAD: Yeah, sure. Anything that’s been deprecated in 5.x, so PHP5.2, 5.3, 5.4, 5.5, 5.6 — are we on 5.7 yet? Anyway, any 5.x release of PHP5, anything that’s been deprecated in those releases is now gone, completely gone. For example, ereg functions, so ereg functions, which are the POSIX compatible regular expression functions. I’ve seen these used in code before. If you don’t use the Perl regular expressions, you would use these ones instead. They’re kind of the alternative, but they don’t exist.

This function search is gone in PHP7. If they’re being used in, say, a plugin that you’re running on your WordPress site, you’re going to get a fatal error if you switch to PHP7 and that plugin is still running.

PIPPIN: Because they’re not just upgraded. They’re actually completely gone.

BRAD: Yeah. It’ll just say, “Function does not exist error,” or whatever, or exception now, I guess. Yeah, so those things are going to have to be addressed, right? Like I said, if you’re moving your WordPress site, you’re actually going to have to know if all your plugins are PHP7 compatible. What else? What else?

PIPPIN: Let’s see. Aside from removing some old stuff, they’ve also deprecated a few new items. If you pay any attention to the Make core WordPress blog, you may have seen the post that was a few months ago. I believe, in the post, they mention that this is kind of a preface to PHP7 coming out. They’ve deprecated PHP for style constructors in classes.

You used to be able to do things like have a class with a name, and then you could put a function in the class that had the same name as a class, and that would be automatically picked up as the constructor for the class. That’s been deprecated. You may have seen that when we talked about PHP for style constructors in widgets because that used to be how widgets worked in WordPress. Those are now officially deprecated in PHP.

You used to be able to get away with having not explicitly declared static methods in a class, and use them statically. Now if you want to use a method in a class statistically, you have to explicitly declare that it is static.

BRAD: Right.

PIPPIN: Otherwise it’s going to throw a deprecated notice.

BRAD: Oh, okay. An e-deprecated notice. Okay.

PIPPIN: Right.

BRAD: It’s not a fatal error.

PIPPIN: It’s not a fatal error, just a notice.

BRAD: Right. Okay.

PIPPIN: It’ll still work. It’s just going to yell at you.

BRAD: Yeah, and usually only if you have, like if you’re in developer mode or whatever. Yeah, huh.

PIPPIN: Those are the big ones. There are a couple others.

BRAD: That’s not that new though, is it? If you have strict standards enabled in PHP5.6, it does yell at you about that stuff too, right?

PIPPIN: Right, but I think that the change now is now it doesn’t require strict standards.

BRAD: Right, right. Okay.

PIPPIN: Now it’s always.

BRAD: Right. Gotcha. There have been some changes to the “foreach.” Have you noticed these ones?

PIPPIN: No, I’m not sure I saw this.

BRAD: Yeah, so “foreach” no longer changes the internal array pointer. When you’re looping through an array, and say you looked through an array and then you ran the function. I think “end” is the function. Any of the functions that take an array and use the internal array pointer, like if you used any of those after a “foreach,” “foreach” actually changed it, so it’s affected. But that’s no longer the case, so that could affect things for sure if you’re anticipating that the internal array pointer has changed through a “foreach.”

These are very nuanced too, right? It’s going to be hard to find that bug.

PIPPIN: Yeah, there are going to be some weird, little bugs that pop up here and there, for sure.

BRAD: Yeah. Then there are other issues with “foreach” as well. “By value” operates on a copy of the array now, so if you’re doing “foreach by value,” which is the default, it makes a copy of the array and then operates on it, which is interesting.

Then, if you’re doing a “foreach” with “by reference,” so you add the little ampersand before the variable, it has improved iteration behavior. That’s what I put in my notes here. I don’t actually know what that means. You don’t know what that means, do you?

PIPPIN: I have no idea what that means.

BRAD: It means something.

PIPPIN: I would assume it means it improved how it iterates over, but that’s about as far as I can go.

BRAD: Yeah, yeah, yeah. Well, we’ll link up in the show notes to the PHP7 migration article, which details all this stuff. It’s actually pretty long too, this thing. We’re only going through the ones that we kind of thought were important, right? There are lots more that we’re not discussing here that are in this document.

PIPPIN: Right. There is one, and I’m going to jump kind of out of order. There’s one change in particular that I think will very likely affect people unexpectedly. There’s a new change in PHP7 related to syntax for variables and classes, primarily. It’s called a uniform left-to-right variable syntax. This one, I think, is going to catch people off guard because they’re not going to expect it. First of all, can you briefly say what this is?

BRAD: Yeah. In the past, when you’re handling variable variables or variables with properties that are variables and methods that are variables, this is going to sound ridiculous because it’s really hard to explain without sketching it on a board or something. Again, I urge you to look at the doc and the examples in the doc.

Anyway, those cases were kind of mixed. They would evaluate left to right sometimes, and then in other times it would evaluate right to left. Now, with PHP7, they decided no, no, no, no more special cases. This is ridiculous. Let’s do left to right, only, strictly. If people want special right to left in certain cases, they can use curly braces to force it to do that.

PIPPIN: Yep. Let’s see if I can come up with an example real quick–

BRAD: Okay, yes.

PIPPIN: –to illustrate this. I’ll be honest. I’m probably going to fail miserably because, Brad, as you just said, this is kind of convoluted and difficult. You really kind of need to visually see this. The show notes will have links to articles that have this.

But, let’s say that you have a class, so you set up an object, and you set this up as a variable. Let’s say it’s a class related of people. You have a class called “person.” I’m actually going to use an example that’s in one of the articles that we’ll link to.

You have a class called “person.” You said, “Person is,” this variable person is a new person. You then set some properties on it. You set the first name. You set the last name. You set some variety of information about it.

Then you define a new variable called “property.” Let’s say that “property” is names. What you want to do is you want to go inside the class, and you want to retrieve the first name of that person. The first name is stored inside of a property.

Man, I’m screwing this up already.

BRAD: It’s hard, man.

PIPPIN: It’s so convoluted. Okay, so imagine the syntax. You have “person” then dash, greater than, property, and then that property is an array. There are two possibilities for what this could retrieve. It could, A: Retrieve the array index inside of the property that you have specified. It could say, okay, “Go into the property and then get this key from the property,” or it could take the variable name that you have passed into the class with that array key as the property name completely. That’s where the left to right really matters.

Instead of taking the array key from the variable that you’ve supplied, it’s going to say, okay, here is the name of the property and, inside of that I’m going to get the array key. It’s going to return that. And so, depending on how you’re calling your methods, if you’re calling them with dynamically populated variables, that’s where you’re going to get messed up because you might have a variable that is an array of property names. You say, “I want this property.” What you get instead is something completely different.

BRAD: I’m just going to take this–

PIPPIN: To give you an example.

BRAD: I’m just going to take this opportunity to apologize to Tina, our transcriber.

PIPPIN: Yes.

BRAD: She is going to–

PIPPIN: Good luck.

BRAD: –have a hard time with this.

A couple things I want to mention before we move on to the new features. There are two things that I didn’t even know existed in PHP until I was looking into PHP7. In PHP5, functions can have multiple parameters with the same name. The variable, like the variable that is the parameter, can have the same name.

PIPPIN: Really?

BRAD: Yeah!

PIPPIN: Why would you do that?

BRAD: I don’t know! I don’t know why you would do that. I guess, say you deprecated three different parameters. You could call them all deprecated. That would be one good way.

PIPPIN: When you say that they can have the same name, does that just mean that PHP won’t freak out at you if you do it? You’ll still get unexpected behavior, but it will allow it? Or is there actually a way to reference each of those parameters inside of your function?

BRAD: Oh, I don’t think there’s a way to reference this. I would imagine one of them gets overwritten. But, yeah, it doesn’t freak out. It just goes with the flow, man. PHP7, no-no, you’re going to get an error in that case.

PIPPIN: That’s probably a good place to get an error.

BRAD: Yeah. You think?

PIPPIN: I cannot come up with one even remotely valid use case for that.

BRAD: Well, I just did. The deprecated thing, I think that one is valid. I might have even seen that before somewhere. Anyway–

PIPPIN: Interesting.

BRAD: Another thing: Switch statements in PHP5 can have multiple default blocks.

PIPPIN: I really like this change, especially because, in every article I found, every time that somebody mentions this they’re like, “There is no logical explanation for why this is supported, so we just fixed it.”

BRAD: Yeah. I’m glad that’s gone too, but I didn’t know about it. I didn’t realize until this article.

PIPPIN: I didn’t either. It makes sense. Why would you do that?

BRAD: Yeah. Okay, should we go on?

PIPPIN: Onto another one. I like that there are two new operators that they’ve added that are cool.

BRAD: Yeah, so you want to move on to new features now, do we?

PIPPIN: Yeah, let’s do new features.

BRAD: Before we do the new features, let’s have a disclaimer. Most of this stuff will not be used if you’re doing plugins for WordPress or themes for WordPress for the masses, and you want to support PHP5.4, at least, right, PHP5.5, 5.6. You’re not going to be able to use any of these. These are all new features that are not going to work in those old versions of PHP. And so, if you want to support them, you can’t use these things.

PIPPIN: A good thing to note about them, though, is that even if you like them, they’re really just handy little tools to have. In no way are we limited by not being able to use them.

BRAD: Absolutely. That’s a good point. Yeah.

PIPPIN: What’s the first one?

BRAD: What is the first one? Scaler parameter types and return types. Oh, yeah! So this is really cool. In PHP5.6 for sure, but I don’t know about the previous ones, you could put, next to your parameter in your function declaration, the object type. Going back to your previous example, you could “person” as the type and then put the variable, “person.” PHP wouldn’t complain about that. In fact, it would enforce that you pass that function, a person object, right?

But you couldn’t use int, float, string, or bool. You couldn’t use any of those types in your function declaration for parameters to enforce a certain type being passed in, and now you can in PHP7.

PIPPIN: That’s excellent.

BRAD: Pretty cool, right?

PIPPIN: It gives you a little bit more control, like if we have functions, just to make sure that they are always giving the exact data type that you want, which is a really big deal if you’re doing calculations or anything like that, making sure that your data types are right if you need to do strict comparisons – just one more way to do defensive coding.

BRAD: Yeah. I don’t know if it’s strict by default. I think there’s a declaration that you have to add to the top of the file.

PIPPIN: I think so. I think you have to … as being strict.

BRAD: Yeah, otherwise, it’s just coercion, which is kind of like PHP’s default.

PIPPIN: Right.

BRAD: For example, if you pass in a string, and it’s looking for an int, it will convert that string into an integer. You see this a lot in WordPress, this coercion. This just kind of happens automatically.

PIPPIN: Sure. One example would be if you need to pass in a post ID to a function, WordPress typically, and PHP in general, allows you to pass in, say, 27, which is your ID, as either a string 27, an int of 27, or I believe you could even do a float or a double at like 27.0.

BRAD: Right. Yep, exactly.

PIPPIN: They’ll all work.

BRAD: Yeah, it’ll just be coerced into the proper type. All of this applies to return types as well, which is new in PHP7 where you can define the type that you want returned by your function. Yeah, you could say bool or string, float, int. All those are supported as well for return types. That’s pretty cool, right?

For example, if your function returned an int, but in your declaration you said it should be a string, it’ll just convert it into a string when it’s returned. Then, of course, if you enable strict mode, it’ll just throw an error, if that was the case. But again, can’t use any of this.

PIPPIN: Right.

BRAD: Most of you can’t use any of this.

PIPPIN: The really good thing is if you’re building a SaaS, or you’re building your own application in a controlled environment and this is not something that you’re releasing to people, or if you are totally okay with releasing a 7 only system, you can use it.

BRAD: Yeah. If you’re building, say, a site for a client, which I know a lot of you are, you could require that the client sign up for, or you could ask your client if they’d be okay signing up for, PHP7 hosting once that becomes available. As far as I know, that is not available right now.

PIPPIN: At least not in most places.

BRAD: Yeah, I don’t know of any hosts.

PIPPIN: I think we’ll start seeing it rolled out once it gets released, but it will still be very limited in availability on hosting accounts for a while.

BRAD: Yeah. Yep. Yeah, I don’t think it’s going to take long because hosts love free power, basically.

PIPPIN: Right. If we look at the upgrade from, say, 5.4 to 5.5, while there were performance improvements, they were not significant. This is extremely significant with the performance improvements. And so, any host that cares about the performance of the sites on it should really be looking at it ASAP.

BRAD: Not only that, but shared hosts are going to love this because they can cram more people onto one server–

PIPPIN: Right.

BRAD: –and before it’s overloaded.

PIPPIN: In 7, there are a couple new operators that are kind of cool. One of them, which is just awesome, I haven’t personally been able to come up with a really good use case for it, but it’s called the spaceship operator or the TIE fighter. I don’t know what the official name is. I think I should look it up.

BRAD: It’s Combined Comparison Operator.

PIPPIN: Combined Comparison, okay.

BRAD: Yeah.

PIPPIN: If you’re looking at it, it’s less than, equal, greater than, in terms of the symbols. The idea for it is you can use it to say, of these two values, is the one on the left greater or the one on the right. It’s going to return either -1 or 1. I hope I have this right. If I have it backwards, tell me.

BRAD: Or zero.

PIPPIN: Right, or zero. There are three potential returns for this. Let’s say that you set up variable A=B<=>C. What it’s going to do is it’s going to look at B and C. If B is greater than C, it’s going to return -1. If the left side is greater, it’s going to return -1. I might have it backwards and it’s going to return 1. If the other side is greater, it’s going to return 1. If they’re equal, it’s going to return 0. You get three potential return values that you can use for these kinds of comparisons.

One of the examples I think that they gave in some of the release notes is if you need to do, like, version comparison checks. It could be the replacement for, say, the version compare function if you need to say, okay, if it’s greater than this, this. Otherwise, do this.

BRAD: Yeah. It’s very similar to the string compare, so STRCMP function, and the version_compare function. I think those are the two that are very similar to this thing. At least, the return the same thing and kind of do the same thing.

PIPPIN: Sure.

BRAD: Yeah.

PIPPIN: Mostly it’s just awesome because it’s called the spaceship, and it looks like a TIE fighter, which is frickin sweet.

BRAD: Yeah.

PIPPIN: Actually, to be more specific, it looks like Darth Vader’s TIE fighter.

BRAD: Yeah. You were pretty excited about this next one. You should probably talk about this.

PIPPIN: I really do like the next one. The next one is the null coalesce operator. It is a double question mark (??).

BRAD: Null, as in null: the value is null, right?

PIPPIN: Right. Up until PHP7, let’s say that you need to determine if a variable has even been defined, if it’s set. What you might do is if it is set A, do this, or else do this. You could do it in a ternary, or you could set it up in an actual conditional statement with brackets. This allows you to determine if a variable has been set, if it’s null or not, without actually having to do “is set.”

If you wanted to set the variable A to a value if B is set, or else set it to, say, variable C, you could just say A??C:B.

BRAD: No colon, actually.

PIPPIN: That’s right, no colon. Right.

BRAD: Yeah, and you can use multiple double question marks.

PIPPIN: Yeah, you could combine them like you could multiple ternaries.

BRAD: Yeah, like you could go A=B??C??D?? and then maybe–I don’t know–false.

PIPPIN: If you want to get really clever, you could define coalesce operators with ternaries and just really confuse people.

BRAD: Yeah. Oh, yeah, this one will definitely be abused. There’s no question.

PIPPIN: It’s definitely a cool one. If nothing else, it’s kind of shorthand – just can shorten some checks for you.

BRAD: Yeah. I love it. Yeah, it’s a nice shorthand.

PIPPIN: I’m sad that I can’t use it.

BRAD: Yeah. I’m depressed. PHP7 makes me depressed and happy. It’s kind of the like the bipolar release.

PIPPIN: Right. It’s like I really, really want to be able to use it right now, and I want to be able to not just use it on my own systems, but use it for users and customers, and be able to take advantage of some of the new syntax, but can’t.

BRAD: Right. Yep.

PIPPIN: What else is new?

BRAD: That’s the world that we operate in here. This one, I’m excited about this because I’ve tried to do this before: define a constant and set the value as an array. You can’t do that right now in PHP5, right? You can’t set a constant to an array. It’ll be nice to be able to do that.

PIPPIN: That’ll be super nice. I just thought of one example. A lot of times it’s very common to set up configurations as constants.

BRAD: Mm-hmm.

PIPPIN: Now, instead of having 10 or 15 constants for your configs, you could have one.

BRAD: Exactly.

PIPPIN: With all of the key values inside of it.

BRAD: Exactly.

PIPPIN: That would be awesome.

BRAD: And because it’s a constant, it can’t be tampered with, can’t be modified.

PIPPIN: Right.

BRAD: Yeah.

PIPPIN: That would be nice.

BRAD: I love it because you see it all the time: define, define, define, define. There’s just tons of defines.

PIPPIN: Right.

BRAD: When it could be one define does an array.

PIPPIN: Define a big array.

BRAD: Yeah. Yeah, exactly.

PIPPIN: That would be excellent.

BRAD: Yep. Yeah, I mean we could go on and on here. I think we’ve covered quite a bit though.

PIPPIN: Definitely covered the important ones.

BRAD: Did we cover why PHP7 and not PHP6?

PIPPIN: No, but that is a really interesting issue. I keep getting tripped up and saying PHP5.7.

BRAD: Yeah.

PIPPIN: Because that’s what I think it is, but it’s actually not. It’s PHP7. There is no 6. What the heck happened to 6?

BRAD: Yeah, good question. I think there’s some drama, some PHP drama. You talk about WP drama now and then. But, no, I think they’d bit off more than they could chew with PHP6. They set a pretty lofty goal of supporting, of building Unicode support into PHP6, and so they had to overhaul all of it. It was just a monumental task, and people got tired and burnt out, is what it sounded like to me from what I read. That’s basically it.

What happened was, though, why we didn’t say, “Okay, well, let’s scrap that, but just keep calling it PHP6,” is that the developers, as they were building PHP6, they were going around to conferences talking about. They were writing articles on the Web, so there was a lot out there about PHP6. And so, it would be super confusing if you were doing a Google search about PHP6 and you came across one of those articles. But it was the new — you know, you were looking for the new PHP6, not the old one that was discarded, so they decided, “Let’s just avoid that confusion and call it PHP7.”

PIPPIN: Right. We have a link to a wiki page on PHP.net that goes over
the history of why PHP7, if you’re interested in it. It’s a good read.

BRAD: Yeah.

PIPPIN: It’s pretty interesting.

BRAD: Very. Very interesting look at how open source goes sometimes.

PIPPIN: Right. It’s also cool because they did a poll, and they
actually voted on whether to do it or not. Some of the primary PHP contributors all voted on it. You can see, they actually even listed what each person voted for on whether or not to name it 6 or name it 7.

BRAD: Yeah.

PIPPIN: Which is kind of interesting.

BRAD: It’s a very open democracy they’re running there with their development.

PIPPIN: Yeah.

BRAD: Yeah, I think it was almost unanimous. I think two people voted against it or something, if I remember right.

PIPPIN: No, not quite that even. It was like 25 to 58.

BRAD: Oh, wow! Okay. I’m thinking about a different vote, I guess. Huh. I think they do a vote for a lot of things. A lot of decisions like that, I think they vote on them.

PIPPIN: That’s cool.

BRAD: It’s interesting.

PIPPIN: Real quick before we wrap up, there’s one more thing. WP Engine and the WP Engine labs have posted actually a testing tool for PHP7 if you want to test it out. We’ll link a blog post up in the show notes, but they have it available as a Mercury Vagrant that you can use to test out PHP7 and see if all your code works. If you’re going to do some testing, which I would highly recommend, go check it out.

BRAD: Yeah. I actually fired that up, and it was really easy. If you already use Vagrant, and you already have the Vagrant set up, it’s super easy to give it a test.

PIPPIN: Awesome. I need to do that in the next couple of weeks.

BRAD: Yeah, that’s a good way. PHP7, right now, is kind of a pain to install, so MAMP doesn’t have it, as far as I can tell. I looked around. Couldn’t figure out a way to get MAMP to load PHP7 into MAMP.
If you’re running Linux though, it’s easy. If you want to replace your native PHP, there’s builds. Zend has builds of PHP7. I think there are nightly builds even that are good for the major distributions of Linux. I think Ubuntu and CentOS binaries, so yeah, it’s pretty easy there. But, yeah, other than that, I’d go with the Mercury Vagrant. It’s super easy just to fire it up.

PIPPIN: Good deal. If you have any questions about PHP7, or you run into issues or anything you want to share, feel free to drop comments on the article, ping us on Twitter. You know how to get a hold of us.

BRAD: Awesome. Thanks, everybody. Talk to you next time.

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply Filters © 2024