 Okay, thanks everyone for coming and apologies about, like, you know, the problems and Windows license and everything. Okay, so this is PHP 7, the vice and the house. This is, well, it gets a little bit technical, but I'm trying to, I'm basically trying to sell a PHP 7, so please try to buy it. Hello, my name is Ayesh, I'm from Sri Lanka. I work in mostly Drupal staff and so coming to history, PHP 5.6 was released back in 2006. So most of us were probably kids back then, 5.3, 2009, 12, and we have PHP 5.6, released in 2014. And right now, the PHP, they don't really support new features. So you're stuck with PHP 5.6. You get, like, security features for some time, but not for real long. So you have to move to PHP 7, it was released 2015, so that's two years already. And we are having PHP 7.2 in one and a half months. So this presentation, I will try to cover some of the features that PHP 7.2 will have. So when you go home, you already know most of the things that PHP 7.2 will have. So it's pretty good. Well, the question is, if it works with PHP 5.6 or whatever the PHP version you have, why do we really bother to upgrade, right? It works, it makes money and the clients don't complain. But, see, the thing with PHP is that it evolves really fast. And new features come, there are some security fixes and everything. So you kind of have to move with PHP, the new versions. And the other one is this is from WordPress. I know this is like DrupalCon, but we use WordPress because it's like terrible code. If you can't like the third line and fourth line, that's like the entire test suite. It took 13 minutes run, and in PHP 7, it took just under six minutes. It's on the same hardware, the same amount of RAMs and the same disk and everything, but it cut like the test time in half. So if you use PHP 7, there's a very good chance that your code will run twice as fast or just twice as less memory. Of course, it depends on each application, but I use WordPress because that's like terrible code. And if you can't get boost from this one, Drupal is like no brainer. You can always get some pretty good advantages. And the next one is like this is DrupalCon again, but we kind of, we are always in PHP community. We just had level 5.5 released about a couple of weeks ago. It requires PHP 7, and we have Symphony 4 coming up probably this year, probably next year. It also requires PHP 7, and Doctrine is an ORM. It's like you manage database entities and everything with it. It requires PHP 7.1, and we have PHP unit. It's a popular PHP testing framework. We used it in Drupal 8, and it also requires PHP 7 now. 7.0. And I'd like to encourage you that if you maintain any open source projects, just click on PHP 7 because it's so much easier. And we'll see how you can actually upgrade your code to PHP 7. So if you maintain any Drupal modules to the left is how you would use in Drupal 7. In your module.infofile, just put PHP equal 7.0, and Drupal will say, if you're running PHP 5.6, Drupal will say, hey, no, you need PHP 7. So you don't have to check the, like the version. You just put it in the module, a module.infofile, and then it would go. This is for Composer packages. I, Composer is a PHP package manager. You can require that if you want to install this package, you have to use PHP 7.0. And no questions here. Composer will make sure that the user has PHP 7.0. So we don't care about WordPress. Now, for Drupal 7.0, sorry, PHP 7.0, these are some of the, if you're not using PHP 5.6 right now, these are some of the pages that you are already missing. So if you are here for the last session, Michelle was contributing to Symphony. Symphony and most of the packages, they use namespaces. So it came with PHP 5.3, and you saw it came like years early, right? And closures, and there's several features that I'm not going to talk about these ones, because it's like 30 minutes, and I wasted with project like 15 minutes. And these are pretty straightforward features, try to understand them. I would personally go for generators and password hashing, the last two. And then short array syntax, you'll probably know this instead of saying like array with like brackets, you just put square brackets and it's just an array. So this is PHP 7.0, I like doggy memes, it looks good with the presentation. Okay, this is the summary, PHP 7.0 now has parameter types. So basically when you define a function and say you need an argument, you can, with PHP 7.0, you can say to PHP compiler that we absolutely need a string or an array, or some integer, or most of the scalar types, booleans, we have plots, we have, we used to have like all class names and everything. And the second one is, it's actually a pretty cool one. With PHP 5.6, if you include a file with say some syntax error, you will get like fatal error, right? It's like in the white screen, we used to have like white screen of dead, like funny names like that. 5.7, you just wrap that call with some try, catch phrase, and you can actually cut that. So we will go to that and asynchronous, we will go through everything. Okay, so this is probably not a really interesting one, but this is most likely the best change we made in Drupal 7, PHP 7.0. Abstract syntax tree is when PHP wants to compile something, it builds the ASD. So it decouples things from like the interpreter and the way the syntax is handled. So it's easier to make new changes in the syntax. That's why we have so many new changes coming because PHP 7.0 was released in 2015, and we already have two more versions. That's one of the reasons why we have faster releases. So if you upgrade your code today, you can kind of like keep up with the changes, and nowadays these changes actually come really fast. So try to catch up, and there are just a few changes you have to make to make them 7.3 compatible, 7.4, so any version that comes after. Okay, this is just an example of one of the features that you have. Now, I hope you can see the screen, right? So earlier, if you're using anything like a condition, you had to use like a set call to see if the variable is set. But the one in the bottom is PHP 7 syntax. You just put two question marks and then set the default value. So if you want to get a variable, and if you want to check that if it's already available, it's like it's already set. You just put two question marks and then set the default value. If the variable is available, PHP will put the variable to the left, and if it's not available, it will use the variable to the right. So after this part, we will try to break the new features to segments. The first one is, again, Michelle last time said that PHP 7.1 has cool new features with types. So PHP is becoming more or less like Java nowadays because we try to enforce strict types. If we say if you're going to return a string, by God, we have to return a string. So the first one is scalar type hints. Scalar variables are variables that are not like part of a class. But strings, integers, Boolean, double, and well, you can see from the example, this is just like a really dumb function. So for this function, when you call this function, you always have to pass an integer. If you try to call it as increase volume with the bool, PHP will throw an error. With PHP 5.5 or 5.6 or any 5x version, you have to check that the variable is actually an integer, like each number or any function code you have. With PHP 7, you can reduce most of the boilerplate code. You just put int and PHP will take care to validate the variable type. And part of the exceptions, I have some slides coming up for that. You can catch them. So if you don't catch them, this would be like a fatal error. You will see like white screen. But you can actually catch them. So not too much to worry about. And then we have return types. It's like when you call get score without this integer, there's no guarantee that it will always return an integer. So it's PHP 7. There's new syntax that you can enforce that this function will return an integer. This is like a contract. So if you put integer, you have to return an integer. So in this case, we return just 110. But if you try to return, say, not available or false or anything that's not an integer, you will get an error. The reason this is good is you don't have to write specific test because this is like a test itself. When you call this, one thing is whoever is calling, they know that you will definitely get an integer. And you can also enforce this one if you use like in a class. Or like every child class that extends this method, they have to return an integer. So it's easier to build interfaces. So if you have like, say, something that others can extend, you can make sure that they will always return an integer. And if they don't, you can easily see the function itself will say this function is supposed to return an integer, but you return this type of string or null or something. So it's really easy to debug. Now with 7.1. Now, by the way, check the title. This one is scalar type hints. If there's no specific PHE version, that came with PHE 7.0. So like this one, it came with 7.1. So try to pay attention to the title as well. This one is like get score. With get score, we definitely return an integer. But this one, we say we will never return anything. Why it is like we don't return anything. So I have put some notes there. You can't return anything other than an integer. Sorry. You can't return anything at all. But PHE 7.1 also has a nullable return type. So in this case, we allow integers and null. But you always have to return something. It's 110. Like it's an integer. You return null. There's no problems here. But if you try to return a string or float, boolean, anything else, you will get an error. And again, this works with methods as well, like class methods as well, not just functions. When you want to mark that return type is nullable, as in it can be null, you just put like a question mark in front of the scalar type. You can use class names as well. Class names as in if you have like a study class or anything that any object from any class, you can just put question mark. So you will return an integer. Sorry. Any variable of that type or nothing at all. It's similar to function arguments as well. So in this case, see the one in red color. Now, usually we have like default values that like a function increase volume increment equal null or some default value. But if you don't give a default value like this, it will always be integer null. You can see that the second example you explicitly have to pass null. If you don't pass null, it will still draw an error. Iterable is something, anything that you can use in for each. Now, usually when we call for each, it's usually an error, right? But there are some new types. Traversable and generators that you can traverse, like you can take one value. This 4-H is wrong. Don't follow that. You can just take a variable and then iterate through each key of these values. So earlier you had to check that it's an array, but technically arrays are not the only ones that you can iterate. So this Iterable type came with Pitch is 7.1 and 7.2. It's not released yet, but with 7.2, you can make sure that every variable you pass is an object. It doesn't have to be a study class. It has to be just any object from any class. So exceptions. In early examples, if you try to violate any of these contracts, I say these are contracts because if you declare that this function takes an integer, you have to do that. If you don't, you will get exceptions, not errors. If you don't catch an exception, well, you actually have some error, but exceptions are PHPs or any programming language way of saying things are not happening the way they are meant to be. So with PHP 5.6, the exceptions we had really sucked because we had three or four exceptions and you had to cover everything. But with this one, PHP 7, we now have an interface called throwable. So every exception is part of child class of throwable. So if you try to catch a throwable, it means almost every error, you can catch almost everything. One in the last one, pass error and type error. Type errors occurred when you violate the contract. Like if you have a function that says it should return an integer and if it doesn't return an integer, that's a type error. If you say a function should take an integer and if you try to pass a string or Boolean, that's a type error. So you can catch them with type error. Pass error is basically syntax errors. If you have a function with some invalid PHP, PHP throw an exception of type pass error, not fatal error, so you can easily catch them. This is just don't worry about it. This is like a new hierarchy. The exceptions to your left is the ones that PHP itself would throw. You can see the same ones pass error and type error. And to your right is some of the functions that you can throw. Now, when you want to make your code really easy to read, if the code is actually a runtime exception, it means there is something going south with the runtime. Just pass a runtime exception. But you can see where I'm going. Try to pass the most logical exception. There are multiple exceptions. You can check them on PHP.net. This is like 30 minutes, so I didn't include everything. Again, this is about exceptions. With PHP 7.1, you can catch multiple exceptions. Okay. I suck at spelling as well. Now, with PHP 7.1, if you have like catch calls, like from the line 3, you can see like there's a catch phrase. So you're trying to catch any exception. But if you do the same thing for all exceptions, you can try to catch everything and execute them at once. So in this case, we try to execute this function, something nasty. And if there's an exception of type PDF exception or full exception, it's not written there, but PDF full exception, PHP will execute the part in the middle for both of these exceptions. You can go with like 10 exceptions, but don't really do that because it makes your code really hard to read. Okay. So that's with the exceptions. This part is it can get kind of technical because with Drupal, now to be honest, Drupal community, we really suck at object-oriented programming because with PHP 5.2, we had like everything was a function and PHP 8, now we have like tons of classes and not everyone's happy. We even have like folks starting, but these are just improvements you can use. If you use object-oriented programming, you can use some of these improvements. First one is anonymous classes. Now, I need honest answer. Who here is writing tests, unit tests, integration tests, anything? Okay. That's really sad. Okay. Well, you should write tests and if you don't, you should feel bad about yourself. Okay. Tests are the way to make sure that your code runs the way it's supposed to be without testing them manually. It's like it takes like tons of time if you want to like go to page, poke some button and see if the output is the same. You can just code that and run it at once. Like in the first few slides, you saw like a screenshot from WordPress. Even WordPress have like unit tests. I'm putting WordPress to like the least level. They even have unit tests, so you should too. With unit tests, there's one concept that we create like a mock-up. It's like something that behaves like the class, but it's not the class itself. Anonymous classes help you to quickly create a class that works like it. You can see from the example for new class, it can extend existing classes and implement interfaces. They can already exist, so they could be like anonymous classes as well. You can quickly create new classes, but I have never seen like any use case outside tests, so if you don't use tests, this slide isn't really for you. Class constraints. For classes, we have these constraints, right? You can never change them, and they are really easy because the class contains like all the constraints and everything, but sometimes there are constraints that we don't really want to expose to outside people. It's like if you use a constraint within your class, you can now with PHP 7.1, we can say this constraint is private, and private means only your class can access it. And we also have protected methods, and public is like the default, so we usually don't put public, so if you want to make like a constraint only accessible to your class, use private. If you want to make a constraint that's accessible to your class or any class is extending it, you can use protected. So it's similar to the same way you use class properties and class methods, so it's like kind of consistent with that. With PHP 7.2, it's not released yet, but you can probably see the difference. This class 4 has method called set ID, and it requires an integer, but we have another class called bar. It also extends 4, but without PHP 7.2, if you do this, you will get an error because these methods, they are not really compatible. Like set ID is int ID, but in bar, it's not, int ID is just ID. So with PHP 7.2, you can just remove this integer and use any class there. So it makes it easier to extend the classes, and kind of violate the contract you have with the base class. And security, I like this part. Now with Drupal, we had a function called Drupal random bytes. It's like 30 lines of code. It tries to see if OpenSSL is available, and if it's available, it tries to get some really random numbers. With this one, you can easily take random int, and it's guaranteed to be really random. Now PHP already has a random function. It says random, but it's not really random, because if you take a million rank calls, it kind of tends to be biased towards something, but random int is more guaranteed to be secure. And then we have like a terrible function called unsterilize. We shouldn't be using it, but people use it anyway. So PHP 7 now has a feature to disable loading classes. Now unsterilize, you can throw any string, and if it validates, PHP will create new classes using that data, but it's kind of dangerous, because now if you try to instantiate, say, a class that's destroying something, it will execute anyway. So with this one, you can say unsterilize function that, no, no, we don't really need any classes there. So it will never try to instantiate any classes. Okay, this is like a terrible point. We have MySQL extension gone. MySQL is not PDO. MySQL is the one that you, like, when, like, three years ago, we used to have, like, MySQL, underscore, connect, and all functions, they're gone. Like, not deprecated, they're really gone. And we have mCrypt is a class, sorry, extension that you use to encrypt files and numbers and everything. It wasn't really maintained for a few years. So we threw that out. Not I did, but someone else did. Ereg is, it's also an older one. We have replaced it Perl regular expressions. And there are two functions. I don't think you have ever used them. So they're gone, but you actually have some replacements as well. Deplications, they're mostly Ph.D. 7.2. So with Drupal 7, we had some count, the third one, some count calls, but they're nowadays gone. So try to don't use them because for everything, if you try to access a variable without the little sign, that basically means Ph.D. used to try and see if there's a variable with the same name. But with 7.2, it will throw an error because it's an error anyway. So it might as well throw an error. AutoloadDs used to be one way to load classes when necessary, but we have SPL AutoloadDs composer. Most of these functions are, like, really old and we should feel bad about throwing them out. And we have two more. Sorry. This is called Uniform Variables Index. This is actually for Drupal people. This is one of the places that we had most errors. When you try to access something from a variable, you can see that it goes, like, deep inside. We take the variable from full and then go inside bar and then try to take bars. Now, before this Uniform Variables Index, PHP would try to get the variable from bar and the key of bars, the second one and the third one. But with Ph.D. 7, it will try to first take a full and then get the bar variable inside and then you can see where this is going. It's always from left to right. So PHP will interpret whatever the variable is to your left and then you try to continue like this. This one is, if you don't use any, like, PHP with command line, this doesn't, this wouldn't make any sense. But if you use, like, Trash or Drupal console or Composer, they are, like, CLI tools. So now, when you want to, like, cancel something, we would just press control C, right? With this one, you can try to catch them. No. Sorry. The one you're in red is that called takes. Well, before this feature, we had to tell PHP that for every second, see if there's any input from the user. And if there's one, just please tell us. With PHP 7, sorry, 7.1, we have this feature called asynchronous signal. So we just tell PHP that if there's signal, just tell us. Just tell me. But we don't tell them when to check them. So they don't check every second. But if there's an input, it will just let us know. It actually gets, like, really cool if you use any CLI tools. You can actually see, like, quite a lot of performance changes. Okay. Dunker is apparently how you say thanks in German, probably now. Then the next one is any questions? Do you have any, if you have any questions? Yeah, we don't have any questions. That's he just asked, have I tried upgrading a Drupal site? Drupal 7 is actually 7.56 is 100% compatible with PHP 7. So if you have, like, a Drupal site, just update to PHP 7.56, and it should work. And Drupal 8 is already compatible. It used to be, like, some long time ago. But don't try with 7.2. There are some problems with 7.2, like, a few warnings. But it should work pretty good. And WordPress, please don't use WordPress. But if you do use WordPress, 4.9 should work well with 7.2. So any other questions? I think some FTP server, not really sure. Okay. Okay, no questions. Okay. And, well, there's some sprints to go. Amanda said me I should put this slide. So I don't really know. And please write the session. If you have any something like solutions, like, if the session was terrible, don't create it. So there's that. If you have any, like, questions about, if you have, like, any troubles upgrading any, like, module, any plugin or something, I'm here all day. So just try to come and see me. Okay. Thanks.