Things you should know about PHP 7
pages.zend.com
pages.zend.com
1. Scheduled to come out in Q4 2015
2. <=> operator, see https://wiki.php.net/rfc/combined-comparison-operator
3. Return Type Declarations & Scalar Type Hints
4. Speed improvements (25-70%)
5. Yep, speed improvements are for real.
You're welcome.
Which won't happen, I can tell you. PHP's release dates always slip by at least a month, and that's without a very unstable master branch like PHP 7 has.
If it does happen, it'll take a few micro (7.0.x) releases until it reaches stability.
> 3. Return Type Declarations & Scalar Type Hints
Also strict scalar typing:
<?php
declare(strict_types=1);
sin(false); // error
strlen(2); // error
However, Zend not mentioning this is to be expected. The company's founders (Zeev Suraski, Andi Gutmans) and employees (Dmitry Stogov and some others) are some of the biggest opponents of strict typing in PHP.-- disclaimer: I am a former PHP internals developer
Umm, well I saw Zeev has voted in favor of scalar type hints on the RFC?
... 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 :-)
Shared Hosting needs to die off anyway.
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.
DO of course have a Wordpress appliance which makes it pretty easy to set up, if you can manage Wordpress you can do it, so long as you're not concerned with getting in to the details of security of your droplet. It's probably no less secure than a lot of virtual hosting arrangements with 777 access on content folders and such.
[If anyone wants a free $10 credit for DO then feel free to message me.]
>"You represent and warrant that you either own or have permission to use all of the material in your Emails." //
Fair use isn't permission, nor ownership, it is statutory right of use though.
They bring in Spamhaus' definition of spam too, which on first reading appears to be self-contradictory - requiring each message sent to be explicitly requested. Taken by the letter this would mean I couldn't, for example, send out a message to a group of customers with whom I had a standing relationship to let them know of a change to terms & conditions, for example, without explicit consent. That means anticipating every email. Catchall phrases like "agree to receive all email" wouldn't work as the customer "has not verifiably granted deliberate, explicit, and still-revocable permission for it to be sent".
Indeed "still-revocable" permission means that as soon as a mass email is sent it becomes spam regardless, it's no longer revocable. There are other problems too - verifiable opt in means an alternate system needs to be used for the verification emails.
In turn that means that any email I send to multiple recipients puts me in breech of Mandrill's T&Cs.
Mandrill have a circular reference from the Terms "You retain ownership of the materials you upload to the Service. We may use or disclose your materials only as we describe in these Terms and our Privacy Policy." and in the Privacy Policy:
>"Information You Provide to Us: When you register to use the Services, communicate with our customer service team, send us an email, or post on our blog, you’re giving us information that we collect. That information may include your IP address, name, physical address, email address, phone number, credit card information, and other details like gender, occupation, and other demographic information. By giving us this information, you consent to your information being collected, used, disclosed, and stored by us, only as described in our Terms of Use and Privacy Policy."
In short the policies allow them to harvest data from emails sent with the service and to use it as they wish. They go as far as to intimate that because they do use the message data internally that the service is not for personal email. There's also a clause Terms 5.f that allows doxing and combining the info with your account data.
The "protections" for selling of your info with the business don't work as there are standard "we can alter this agreement unilaterally" conditions.
tl;dr law - it's complicated. This service is absolutely not for "personal" emails however.
Sensitive emails contravene the T&C; I think those examples would be included in that definition.
The alternatives seem to be giving customers a VM or a dedicated server which tends to mean it's _never_ going to get any security updates since the day it was first set up.
Shared hosting is a pain, but the alternatives have the potential for even more pain.
Edit: it was RH7, not RH5. Just checked. Still bad.
This is like saying "Bicycles need to die out." just because you never ride one.
Disclaimer: I work for a web hosting company.
You could say the exact same thing about VPS servers compared to dedicated hosting and be equally wrong. Please accept that there are different use cases that come with different solutions, of which shared hosting is one.
I work for a shared/dedicated hoster, we're geared price-wise at the higher end of the market and we provide shared hosting for our business customers.
Our shared environments are closely monitored and never oversubscribed. We're constantly looking out for customer sites that misbehave and shut down those that are resource hogs or service affecting.
We have loads of customers running the internet facing parts of their businesses on shared.
Shared hosting, like all other things, is a case of "you get what you paid for".
It tends to be a classic case of blaming the tools for the actions of the people using them.
For example, people track link clicks in a web app and they do it with Google analytics. If not handled correctly, it will break all the navigation on a page.
Seems like the only new feature are type hints. Looks like Hack has been rebranded as PHP 7.
The speed boost is due to massive engine changes and internal refactoring.
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 (??) (https://wiki.php.net/rfc/isset_ternary)
- Closure::call (https://wiki.php.net/rfc/closure_apply)
- Abstract syntax tree (https://wiki.php.net/rfc/abstract_syntax_tree)
- Context sensitive lexer, allowing the use of reserved words in more places (https://wiki.php.net/rfc/context_sensitive_lexer)
- Unicode escape syntax in strings (https://wiki.php.net/rfc/unicode_escape)
- A uniform variable syntax (https://wiki.php.net/rfc/uniform_variable_syntax)
- Expectations (https://wiki.php.net/rfc/expectations)
- Use declaration grouping (https://wiki.php.net/rfc/group_use_declarations)
- Removal of a ton of long-deprecated features
- Massive speed improvements
You can see everything that's been added to PHP 7 on https://wiki.php.net/rfc (look under Accepted and Implemented - PHP 7.0)
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.This is not meant to be an endorsement of this method, but PHP <7.0 uses a single-pass compilation where the parser itself does the opcode compilation. A lot of the buggy and quirky behavior PHP exhibits (at least when that behavior is unintentional) is the result of this process.
Like a lot of extant PHP, there's no real reason it was done this way: it's just the method Rasmus et al happened to program the original engine, and it's grown organically since then. With the AST, phpng, and the uniform variable syntax, I'd argue PHP7's main feature is finally getting around to correcting the sins of the past.
A lot? Please stop spreading wrong info. In the words of an internal developer,
> It does fix a few minor points with regard to variables vs. expressions, but those aren't particularly important.
>"So, really, the whole thing has no direct effect on userland devs. It's an internal rewrite."
https://www.reddit.com/r/PHP/comments/2cc9xp/rfc_abstract_sy...
You may disagree with me saying "a lot", and that's fair, but I don't think it's fair to say it's "wrong info" and NikiC's characterization that it has "no direct effect on userland devs" is disingenuous, given the RFC lists several changes to syntax and behavior: https://wiki.php.net/rfc/abstract_syntax_tree#changes_to_syn...
On a side note, does anyone know why Drupal 8 is apparently so absurdly slow? I know it's not entirely fair to compare against D7 as it's still technically "under development" but it just seems insane to take that much of a performance hit for nicer OOP semantics...
Once the debug flag is turned off, Symfony won't check the freshness of the dependency container as well as templates, bootstrap caches, etc. (you clear the cache manually in production.)
As to what the Drupal devs may have added on top of the framework, I have no idea. Being a generic CMS, I presume their abstractions are a little bit overengineered.
Frankly I don't really see drupal's place in the world anymore. It's so absurdly config-heavy, which may have made sense a decade ago but not now. Everyone will just install composer, put laravel/symfony on there, and be off to the races. The era of giant pages of drupal-managed plugins is over, and replaced by package managers + slimmer CMSes like joomla or concrete5.
I'm really excited for D8, no other CMS to date has been as easy to administer in my eyes, and now that they're dramatically revamping the module and theming stories I may even enjoy writing modules and themes once more.
My point is I think the fundamental idea of drupal is obsolete. If it can eke out a few more years of relevance and take market share away from WordPress, all the more power to them,
Having worked with many PHP CMSes, the config for managing various drupal plugins is often far more complex to setup, maintain, and migrate than simply writing that feature in my own little class in concrete5, joomla, or even without a CMS. I get the appeal behind wordpress (even if I think it's implementation is complete garbage), because non-technical people can still setup and manage their plugins. Most of my clients who are/were on drupal, became my clients after they were inevitably crushed under a pile of drupal config.
Drupal seems great for a content-heavy site that caches well. Personally, I would not build an account-based, heavily personalized web app in Drupal unless I knew the audience was pretty small.
Even in the dinky D7 sites I've run, we got significant performance improvements just by handing off search and commenting to services other than Drupal (SOLR and Disqus).
See this reddit comment,
http://www.reddit.com/r/PHP/comments/2zhg6z/how_true_is_this...
and tell me what you think about it. When stuff like this exist, does it matter if it gets all the shiny new features and speed improvements? Not to mention that by php's development culture, these new features probably end up half baked and with it's own set of weird behaviors...
There are lots of improvements going in to make it 'fast by default'.
That's still around, even on Hacker News. Tons of comments in poor taste from posts about 3 months ago as I remember it
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 :)
But competition is good, great actually. HHVM recently folded in JIT regex like PHP7, so they are copying from each other.
It, directly or indirectly, fixes a lot of horrible behaviour. PHP's absurd comparison operators, for instance, are safely usable once you drop them into a statically typed environment.
Unlike PHP, Hack lets you, nay, encourages you, to turn off type checking in places
Scalar type hints are a bit of a no-brainer. Type-hinting classes is nice, but there's a lot of sloppiness out there because if you can't type hint as a scalar, not only do you need a separate check to see if it's int or string, you also specifically cannot say it's non-object/array in your function declaration. One of the biggest inconsistencies I see, especially on old CMSes, is where you'd have a method in one class like `function doThing(Page $page) {`, and elsewhere as `function differentThing($page) {`, and sometimes differentThing's $page is a Page, other times it's an int with that page's ID or name. Yes there are all kinds of ways to check for that today, but it benefits everyone if the easiest way to do something is also the right way.
Return type declaration has been in Hack for a while, and it's really handy there. Any C or Java programmers know how useful they are. My big hope here is that they encourage others to stop returning mixed-types, which is a pattern that inevitably just puts more control logic around every call to that function. I don't care too much about nullable type-hints on parameters (you can still set a default `= null` to allow nullable), but I'm _really_ hoping the nullable return-types passes. Having worked with this for a while in Hack, return types are far more useful if they're nullable. e.g. you say `function isUserActive(): bool`, that's totally fine since you're clearly expecting it to be true or false, but if you had `function getActiveUser(): User`, you'd want the option to return null if there is no active user, which could be done nicely as `function getActiveUser(): ?User` if this passes: https://wiki.php.net/rfc/nullable_types#return_types
Now that we're finally actually making a proper PHP spec, I'm not as excited about 4 and 5 as they'd like us to be. It's definitely faster, but if the Zend engine isn't the only game in town, it doesn't matter as much. All the HHVM benchmarks I've seen still put it way above PHP7.
I was the only person who seemed to care much about the spec, and I quit. The spec has several broken tests, numerous omissions and inaccuracies, and doesn't mention any of the really important PHP 7 features.
I'm not too optimistic.
Sure, there's PyPy but it's not compatible with the mainstream C-Extensions so pretty much a no-go for most of my projects. Hopefully Piston will come to rescue in the future.
I haven't benchmarked either though.
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, but it might in many others that don't spend as much time (de)serializing.
> function add( ... ): float {}
I think a much better choice would have been:
> float function add( ... ) {}
Or just:
> float add( ... ) {}
Since that's how it's done in other languages and people would feel at home with it.
The thing you mention ("float function add(){}") keeps the option to search for "function add", but I am unsure why this is not taken into account in this proposal.
Anyhow, I am pretty happy this finally made it to the php language.
[1] https://wiki.php.net/rfc/return_types#position_of_type_decla...
Which if you read it out, it sounds entirely natural "This is a function called foo, which takes some params, and returns a float". Most of the other variants don't read as naturally.
> Since that's how it's done in other languages and people would feel at home with it.
PHP doesn't need to copy the mistakes of other languages. It's got plenty of its own mistakes.
It makes very little sense for PHP. A function definition now even has both styles:
`function foo(argtype arg) : rettype` instead of `function rettype foo(argtype arg)` or `function foo(arg : argtype) : rettype`.
But then, it wouldn't be PHP if it was too consistent ;).
function foo(a:int,b:string):bool{}
in PHP this will be function foo(int a,string b):bool{}Everything old is new again.
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 <popular language from the 1970s> 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 )This is not to say that PHP won't work fine for many people; I just don't care for the (several) directions PHP is going in.
I have not detected any fragmentation. In fact, HHVM's speed of development has been a much needed kick in the pants to PHP.
The fact that it took over a decade for a language specification to appear is less so.
PHP-NG/PHP 7's troubled birth, and its contention with HHVM, does not bode well for PHP's future. I feel like it's going the route of Perl 5/6;Python 2/3.