The PHP 5.4.0 release is
available. "This release is a major leap forward in the 5.x series,
which includes a large number of new features and bug fixes." Those
new features include traits, some array syntax
improvements, a built-in web server, performance improvements, and
more. See the
changelog for lots of details.
(Log in to post comments)
PHP 5.4.0 released
Posted Mar 1, 2012 23:40 UTC (Thu) by apoelstra (subscriber, #75205)
[Link]
For those wondering, the difference between a trait and an interface is that a trait also defines a default implementation for its methods.
For whatever reason, most summaries of the 'trait' concept fail to mention this, and therefore it may look like traits and interfaces are identical.
You can use the magic constant __CLASS__ to get the name of the specific class you are calling from (__TRAIT__ will give you the name of the trait), and a trait can call any public method of a class that uses it.
PHP 5.4.0 released
Posted Mar 2, 2012 10:35 UTC (Fri) by angdraug (subscriber, #7487)
[Link]
Thanks, that's very helpful. From the looks of it, PHP traits are implement the concept of Mixin, did they have a reason to make up their own name for it?
PHP 5.4.0 released
Posted Mar 2, 2012 12:11 UTC (Fri) by oseemann (subscriber, #6687)
[Link]
Maybe because Mixins are ideally used with multiple inheritance, where you inherit from the base class plus any number of mixins. PHP only does single inheritance, if I am not mistaken.
PHP 5.4.0 released
Posted Mar 2, 2012 12:21 UTC (Fri) by angdraug (subscriber, #7487)
[Link]
No, mixins were invented specifically to avoid multiple inheritance when reusing code from multiple classes. They only exist in languages with single inheritance. According to that Wikipedia article I linked to earlier, PHP traits are mixins, which is why I'm curious why they had to invent their own name for a well-known concept.
PHP 5.4.0 released
Posted Mar 2, 2012 15:25 UTC (Fri) by pboddie (subscriber, #50784)
[Link]
At least as far as I have seen, mixins/mix-ins in their most general sense are actually intended to avoid multiple inheritance of common functionality or concerns, and they actually rely on a viable multiple inheritance mechanism. So, you would make a class inherit from several mix-ins associated with orthogonal or non-overlapping functionality, concerns or concepts, potentially incorporating code from each of them (hence the need for functioning multiple inheritance), safe in the knowledge that you won't run into weird invocation order or initialisation problems which arise when it turns out that various classes you've inherited have a common ancestor.
PHP 5.4.0 released
Posted Mar 2, 2012 15:46 UTC (Fri) by rfunk (subscriber, #4054)
[Link]
I think it's a matter of your definition of mixin and ultiple-inheritance. Support for mixins can be a way for an otherwise single-inheritance language to support a form of multiple-inheritance. Does that make it a multiple-inheritance language?
The specific example I'm familiar with is Ruby, which supports mixins ("modules"), but is otherwise an explicitly single-inheritance language. It uses a form of implicit ordered search path/chain to determine which method runs if there are multiple candidates.
PHP 5.4.0 released
Posted Mar 3, 2012 0:24 UTC (Sat) by pboddie (subscriber, #50784)
[Link]
Well, if we distinguish between inheritance (meaning the adoption of code, its interfaces and potentially attributes or members from a parent abstraction) and conformance (meaning the adoption of an interface from an abstraction), it seems to me that the latter isn't enough to give you mix-ins. So in Java you traditionally couldn't mix functionality into a class from more than one superclass, but you could declare conformance to a number of interfaces, but that would still leave you with filling in the missing functionality in a concise fashion. Mixing typically implies the involvement of more than one thing, and single inheritance doesn't really provide much scope for that. I suppose that these traits allow the inclusion of code originating from outside any defined conformance hierarchy, which reminds me somewhat of aspect-oriented programming, if I recall the nature of that correctly.
I've used mix-ins in Python where multiple inheritance is possible (according to the above definitions), but where you want to avoid method resolution uncertainty or general untidiness, although I'd argue that architectures based on mix-ins can be quite stifling and that other mechanisms exist in Python that are preferable (mostly due to Python's dynamic typing and objects-as-callables support).
PHP 5.4.0 released
Posted Mar 2, 2012 22:55 UTC (Fri) by robert_s (subscriber, #42402)
[Link]
"No, mixins were invented specifically to avoid multiple inheritance when reusing code from multiple classes. They only exist in languages with single inheritance."
The term (& technique) is very heavily used in the Python world to perform exactly what oseemann is describing.
PHP 5.4.0 released
Posted Mar 3, 2012 0:49 UTC (Sat) by elanthis (guest, #6227)
[Link]
It's not true to say that the only exist in languages with single inheritance.
There's plenty of reason to have them even with multiple inheritance. Mixins can implement part of one or more interfaces, can include new members and methods, and -- this is most important -- can freely call into the class using the mixin.
In C++, which has no mixins, it is common to use a template to implement a mixin. Unfortunately it is not a "real" mixin due to various limitations the inheritance-based approach imposes. You can work around most of those with a lot of overly verbose syntax using CRTP, but it'd be nice if you didn't have to.
PHP 5.4.0 released
Posted Mar 2, 2012 15:40 UTC (Fri) by rfunk (subscriber, #4054)
[Link]
PHP has a strange habit of using slightly wrong nomenclature when they add "advanced" features, so I'd rather they just made up their own name than get it wrong.
(The particular example I'm thinking of is using "closures" to mean "lambdas" or "anonymous functions", while in fact actual closures are clumsy there.)
PHP 5.4.0 released
Posted Mar 2, 2012 16:20 UTC (Fri) by artem (subscriber, #51262)
[Link]
I just checked some of the languages that wikipedia article claims to support 'Mixin' concept:
Scala - uses 'trait' to denote classes that you can 'mix in' into other classes
Ruby - does not use the word 'mixin'
Groovy - uses @Mixin annotation for classes that have other classes 'mixed in'
Vala - does not use the word 'mixin', just allows to define methods in interfaces
So 'Mixin' is just a vague concept, and you have to be precise when defining a language. And it just sounds weird - trait is so much better IMHO.
PHP 5.4.0 released
Posted Mar 2, 2012 19:03 UTC (Fri) by rfunk (subscriber, #4054)
[Link]
Ruby doesn't use the word "mixin" itself, but the Ruby community does.
PHP 5.4.0 released
Posted Mar 2, 2012 21:31 UTC (Fri) by artem (subscriber, #51262)
[Link]
So, I see it as PHP agreeing with Scala and disagreeing with Ruby in their choice of the name. They did not invent their own name.
PHP 5.4.0 released
Posted Mar 2, 2012 7:27 UTC (Fri) by b7j0c (subscriber, #27559)
[Link]
the two big php bugs are still open:
1. it exists
2. people use it
yeah 5.4 has some moderate changes. array literal syntax! welcome to 1992.
traits should be amusing. even more rOOPe for novices to hang themselves with.
utf8 is now the "default charset" you'll have to explain what that means since php strings still can't natively accept unicode without mb_* hacks.
it has some good points
Posted Mar 2, 2012 10:26 UTC (Fri) by alex (subscriber, #1355)
[Link]
I know PHP has a bad reputation for both the language and the people that use it. But lets not knock it too much. For all it's flaws it remains a very quick way for people to define moderately complex programmatic server side generated web-pages. Coming from a time when the alternative was the basic Perl CGI approach it's a testament to the language that beginners were able to pick it up and get stuff running pretty quickly.
Instead of sneering at the flaws and non-leetness of it's users we should be offering to show people who have cut their teeth on PHP how things can be achieved on modern server side systems.
PHP 5.4.0 released
Posted Mar 2, 2012 12:55 UTC (Fri) by Kit (guest, #55925)
[Link]
So what language is actually better suited for the job that PHP is used for all the time?
People bash PHP all the time, and I'm really not a fan of it, but when I get right down to it... it's hard to point to any of the alternatives and say 'this is better'. If you ignore that so many of the people that give PHP advice give absolutely awful advice (such as encouraging the use of the old mysql(i)_* functions, which make SQL injection child's play, instead of PDO), since if it wasn't for PHP they'd likely give awful advice in another language... It's really hard to point to major issues with PHP.
PHP 5.4.0 released
Posted Mar 2, 2012 13:07 UTC (Fri) by Cyberax (✭ supporter ✭, #52523)
[Link]
How about Python or Ruby? Or Java, Scala, Groovy, C#?
PHP 5.4.0 released
Posted Mar 2, 2012 13:20 UTC (Fri) by sorpigal (subscriber, #36106)
[Link]
The problem with PHP, for me, is that it copied Perl, copied it badly and is now in a perpetual process of catching up with fixes Perl has had for years. Just use Perl with an appropriate web-friendly framework and you get all the nice things about PHP without any of the nastiness of actually using PHP.
PHP 5.4.0 released
Posted Mar 2, 2012 15:50 UTC (Fri) by rfunk (subscriber, #4054)
[Link]
Yeah but then you get all the nastiness of using Perl! ;-)
(I grew up on Perl. Switched to PHP, then to Ruby. When I went back to Perl for a while it was nearly unbearable.)
PHP 5.4.0 released
Posted Mar 3, 2012 15:53 UTC (Sat) by cmccabe (guest, #60281)
[Link]
Posted Mar 8, 2012 15:08 UTC (Thu) by Los__D (guest, #15263)
[Link]
No, that is a ridiculous page written using the conclusion-first approach.
PHP 5.4.0 released
Posted Mar 2, 2012 13:24 UTC (Fri) by khim (subscriber, #9252)
[Link]
So what language is actually better suited for the job that PHP is used for all the time?
Well, PHP is perfect for the “I don't want to learn programming, yet I still want to create something kinda working and I don't care about the fact that my site with be pwned in hurry” work.
People bash PHP all the time, and I'm really not a fan of it, but when I get right down to it... it's hard to point to any of the alternatives and say 'this is better'.
There are tons of better alternatives if your goal is to create something robust. C#, Java, Perl, Python, Ruby, etc. Sure, they don't try to “help” you thus you actually need to think when you use them, but this is the only way to create working programs anyway.
If you ignore that so many of the people that give PHP advice give absolutely awful advice (such as encouraging the use of the old mysql(i)_* functions, which make SQL injection child's play, instead of PDO)
Why these are awful? Don't cry for your hair… when they've chopped your head off. If you are using PHP then your goal is by definition to create something “kinda working… if not stressed” and mysqli functions are easier to use.
The best example of PHP's brain-dead interface (for the sake of simplicity, heh) is not even MySQL. It's pcre. Observe how pcre_compile is missing - for the sake of simplicity, of course. Well, for short strings pcre_compile takes 100 times more resources then pcre_exec so PHP just forced you to waste 99% of resources for the sake of “simplicity”. Congratulations!
Of course if you'll define a typical PHP programmer as someone who can not learn to correctly use couple of functions then there are no alternative to PHP - but is it even possible to create such alternative? Why will you want it?
PHP 5.4.0 released
Posted Mar 3, 2012 19:48 UTC (Sat) by judas_iscariote (subscriber, #47386)
[Link]
It does not have pcre_compile because already compiled regular expressions are stored in a memory cacne ....
PHP 5.4.0 released
Posted Mar 2, 2012 13:41 UTC (Fri) by osma (subscriber, #6912)
[Link]
So what language is actually better suited for the job that PHP is used for all the time?
That's a very good question. If the job is to add a little bit of server processing to otherwise static HTML pages (which I think is the original PHP use case that then got a bit out of hand), then there's not much competition. I guess nobody does SSI any more and it's very limited in any case. There's PSP in mod_python, but I doubt it is used much either.
Using all the other languages tends to require more infrastructure. Often you need to run another HTTP server process besides Apache. With PHP, you can just install mod_php and immediately add bits of code into your HTML files. That's not a good idea if you need to do big applications, but it's a very easy way to at least get started with server-side programming (plus with HTML5 you can do a lot on the client side nowadays, so often you just need a little bit of server-side logic). It's also quite easy for ISPs to support running small PHP scripts so it tends to be available in a lot of environments.
PHP 5.4.0 released
Posted Mar 2, 2012 16:53 UTC (Fri) by jmalcolm (guest, #8876)
[Link]
> So what language is actually better suited for the job that PHP is used for all the time
I am not here to bash PHP although it might come off a bit like that. I have two answers depending on context:
1) If we mean, "better" at creating "professional" server-side web applications
Depending on your definition of "professional", the answer would be pretty much any other language commonly used on the web. This would include Ruby, Python, Java, C# and others. I think that the reason most people deride PHP is because it's natural style and internal inconsistency does not meet their definition of "professional".
2) If we mean, "better" at cranking out dynamic web pages with a minimum of theory, infrastructure, ceremony, and magic then PHP stands almost alone (which is probably your point). It is worth pointing out though that the primary reason for this is because almost everybody else has abandoned the inline script style of web development. For example, both ASP (Microsoft) and JSP (Sun) are years behind us but both were very PHP-like.
If I remember correctly, Microsoft Web Pages (their Web Matrix intro environment) is a lot like PHP but without so many of it's warts. Also, you can at least mature in that environment to a full ASP.NET MVC paradigm with reasonable continuity. You can do it on Mono as well if you want Open Source. That statement might cause a flame war so I will just point out that Microsoft themselves use Mono in a few places (including tryfsharp.org and some apps/games in the iPhone App Store as examples).
Of course, the PHP community is quite diverse and there are, for example, MVC frameworks available for PHP. At that point though, the uniqueness of PHP goes away. Other than already knowing PHP, I am not sure I see the advantages of a PHP MVC framework over choosing something else.
PHP 5.4.0 released
Posted Mar 2, 2012 17:24 UTC (Fri) by rfunk (subscriber, #4054)
[Link]
The big advantages of PHP are its ubiquity on servers (where we don't always get to dictate what's there), ease of deployment, and ease of finding someone who knows it. (Though most of those people aren't actually very good at it.)
It's easy to find languages that are better at any other attribute you could name, but those two or three are the reasons PHP is still used, even by those who dislike it.
PHP 5.4.0 released
Posted Mar 2, 2012 17:44 UTC (Fri) by niner (subscriber, #26151)
[Link]
So in short: PHP is used because PHP is used. Jay network effects! Keeping garbage technology alive for decades...
PHP 5.4.0 released
Posted Mar 2, 2012 18:08 UTC (Fri) by jmalcolm (guest, #8876)
[Link]
Hosting gets mentioned lot and it was true at one point. Honestly though, that statement is no longer true as far as I can tell. It may be that there are hosts that only support PHP but it is certainly easy to find good quality hosts at any price point that support lots of other stuff as well. Ruby, Python, Perl, ASP.NET and others are all pretty common even on $7/month plans.
If you pick a host at random, I expect that they will support ASP.NET at the same price points as PHP.
"Finding someone who knows it" is an interesting one. Skills in other languages are not exactly rare but I imagine that it is probably true that there are more people exposed to PHP. If we change the task to finding somebody "who knows what they are doing", it could be argued that it is no easier to find this in PHP-land than elsewhere. In fact, the task may even be easier for other languages.
Deployment is also interesting; I could say a lot about it but I will give you that one. Well, I will say that if you find a dev "that knows what they are doing" it pretty much becomes a non-issue. One of the things that many people (that I have known) really love about PHP is the ability to edit in-place in production. That is of course really nice and completely horrifying at the same time.
PHP obviously fills a need as it keeps on going strong. One might expect a competitor to emerge that addresses PHPs warts while offering it's attractive characteristics. I think that your three issues ("broad exposure, ubiquitous hosting, and no-fuss deployment) are big factors. If I create a "better PHP than PHP" I will not attract many Node.js, Rails, or ASP.NET developers. Sadly, the lack of millions of tutorials and hosts for my "better" platform will keep the would-be PHP devs away too.
PHP keeps evolving though. With the addition of traits it has something many languages lack (including C#). The need to stay compatible holds the language back but someday (far from now) there may be a subset of PHP which is nice. Keep your eyes peeled for the book "PHP: The Good Parts".
PHP 5.4.0 released
Posted Mar 3, 2012 0:23 UTC (Sat) by rfunk (subscriber, #4054)
[Link]
Who among us wants to do ASP.NET? :-)
Part of hosting is in the corporate world, where things are slow to change. One major client I work with gives the option of Java or PHP for hosting -- and until recently that was only PHP 5.2.
And that leads into the deployment issue, where PHP is really the only major platform where an Apache module is a viable option. (Yes, mod_perl and mod_python exist; the former is painful in my experience, and I never hear about anyone using the latter. Then again I've never been a Python guy, and I find most Perl work painful anymore.) Everything else either uses CGI (slow), or uses a separate application server architecture, with inherent complexity. With that sort of architecture, having someone who knows what they're doing is necessary, but that doesn't make all the pain go away.
I'll be interested to see if Node.js, or something like it, ends up going more toward the PHP-ish route, or more toward the Ruby/Rails-ish route. (Ruby and Rails are already more on the Java path.)
I definitely like the "Good Parts" idea for PHP... except that the book already exists. http://shop.oreilly.com/product/9780596804381.do
It's not nearly what the Javascript original was though.
PHP 5.4.0 released
Posted Mar 3, 2012 7:47 UTC (Sat) by Cato (subscriber, #7643)
[Link]
If you want some degree of security, you need to use CGI not mod_php on any host with more than one application owner, e.g. shared web hosting. And CGI is slow, so it's better to use FastCGI (i.e. separate PHP server to web server) so your web app can run as the right userid yet not pay the CGI startup overhead. This is essential for more complex apps or higher volume websites, which also tend to require some security.
I believe Ruby and Python are often deployed in the same way.
PHP 5.4.0 released
Posted Mar 3, 2012 14:50 UTC (Sat) by rfunk (subscriber, #4054)
[Link]
PHP-FPM is a much better solution than fastcgi if you need that sort of thing; people who are running Apache (and therefore don't have huge traffic issues) generally don't though. For shared hosting, suPHP improves security greatly by running as the user who owns the file. (However, I haven't really paid much attention to shared hosting myself.)
I can't speak for Python, but the Ruby world abandoned fastcgi years ago because of its many problems, in favor of Java-style middleware layers.
PHP 5.4.0 released
Posted Mar 3, 2012 15:28 UTC (Sat) by Cato (subscriber, #7643)
[Link]
Actually PHP-FPM is a FastCGI implementation, with the F standing for FastCGI: http://php-fpm.org/
suPHP is similar to suexec and often used with CGI but that doesn't change my point that mod_php is not used on shared hosting (or at least responsible shared hosting).
On Python and Ruby, I just meant the principle of having a persistent interpreter process running outside the web server, not FastCGI specifically.
PHP 5.4.0 released
Posted Mar 3, 2012 15:47 UTC (Sat) by rfunk (subscriber, #4054)
[Link]
Ah, sorry, I was actually thinking of suexec when I said suPHP. Either way, I'm not very much concerned with shared hosting.
I see a big difference between fastcgi and using an application server, possibly because I remember the pain of using fastcgi with Ruby, and the major differences when I set up an application server instead.
PHP 5.4.0 released
Posted Mar 5, 2012 8:39 UTC (Mon) by colo (subscriber, #45564)
[Link]
Not necessarily true; using Apache's mpm-itk, you can achieve the same level of security/privilege separation that you have with (f)cgi and suexec with e. g. mod_php as well.
PHP 5.4.0 released
Posted Mar 5, 2012 8:50 UTC (Mon) by anselm (subscriber, #2796)
[Link]
Privilege separation isn't the only advantage of setups like FastCGI or WSGI that keep the language interpreter separate from the web server. Another advantage is that you get to proxy only those requests to the language interpreter that actually need it, while requests for, say, small static image files don't occupy expensive language-interpreter-containing Apache processes. This is probably the #1 thing you can do to speed up dynamic web sites.
There are of course other ways of achieving this – e.g., by putting a more lightweight web server in front of your Apache/mod_php to serve any static content and have that server proxy only the PHP stuff to the actual Apache, or by serving static content from a different server altogether –, but mpm-itk isn't one of them.
PHP 5.4.0 released
Posted Mar 3, 2012 16:47 UTC (Sat) by jmalcolm (guest, #8876)
[Link]
Thanks for pointing out "PHP: The Good Parts". I should have done a search before making that comment.
Is it worth a read? I do not do much PHP but I am curious what that book would have to say.
PHP 5.4.0 released
Posted Mar 5, 2012 8:04 UTC (Mon) by cmccabe (guest, #60281)
[Link]
> Thanks for pointing out "PHP: The Good Parts". I should have done a
> search before making that comment.
>
> Is it worth a read? I do not do much PHP but I am curious what that
> book would have to say.
Unfortunately, all the pages in the book are blank, for obvious reasons.
Ok, ok, sorry. I couldn't resist.
PHP: The Good Parts
Posted Mar 5, 2012 21:30 UTC (Mon) by rfunk (subscriber, #4054)
[Link]
I have the book (or I thought I did, though so far I've only found my epub file), but haven't spent much time with it. It starts off with PHP basics, and I'm familiar enough with PHP that I wasn't motivated to dig further at the time.
PHP 5.4.0 released
Posted Mar 3, 2012 20:28 UTC (Sat) by jmalcolm (guest, #8876)
[Link]
> Who among us wants to do ASP.NET? :-)
> PHP is really the only major platform where an Apache module is a viable option
I think that mod_mono makes ASP.NET quite viable on Apache. So, I guess that would be one reason. Technically, mod_mono invokes mod-mono-server so I guess it means what you mean by "application server". As far as complexity goes, it is just a couple of lines in your httpd.conf (or a .conf that httpd.conf refers to).
I need to get off the Mono advocacy stage though. This is a PHP thread.
PHP 5.4.0 released
Posted Mar 2, 2012 21:40 UTC (Fri) by Kit (guest, #55925)
[Link]
> 2) If we mean, "better" at cranking out dynamic web pages with a minimum
> of theory, infrastructure, ceremony, and magic then PHP stands almost
> alone (which is probably your point).
This is exactly what I was getting it. PHP is nice because you can just sprinkle a little bit on some raw (already existing!) HTML and then have some server-side magic on your website. I'm not talking about creating a web _app_, which seems to be the only thing anyone else considers a legitimate use case anymore.
I also see value in allowing non-developers to be able to do server-side processing on websites, without having to spend an inordinate amount of time learning largely superfluous concepts for their actual needs. PHP has never seemed amazing in that regard, due to some simple ways to shoot yourself in the foot (Remote File Inclusion being the biggest IMO)... but, it seems that there's no other language that even tries. It seems everything else targets either very low, or very high, with nothing much really even coming close to that middle ground.
PHP 5.4.0 released
Posted Mar 8, 2012 22:19 UTC (Thu) by HelloWorld (guest, #56129)
[Link]
> This is exactly what I was getting it. PHP is nice because you can just sprinkle a little bit on some raw (already existing!) HTML and then have some server-side magic on your website.
Pretty much any language can do that. There's HTML::Mason for Perl, Spyce for Python, eRuby for Ruby etc.. People just keep making up fairy tales about how PHP is so much easier than the alternatives, but it's simply not true.
PHP 5.4.0 released
Posted Mar 2, 2012 19:36 UTC (Fri) by HelloWorld (guest, #56129)
[Link]
> So what language is actually better suited for the job that PHP is used for all the time?
>
> People bash PHP all the time, and I'm really not a fan of it, but when I get right down to it... it's hard to point to any of the alternatives and say 'this is better'.
No, it's not hard at all. Python, Ruby and Perl are all vastly superior to PHP. The sad truth is that PHP is a steaming pile of crap that should have died a gory death a long time ago.
PHP 5.4.0 released
Posted Mar 2, 2012 21:49 UTC (Fri) by Kit (guest, #55925)
[Link]
I probably poorly worded it, but I wasn't wanting simply a list of languages (which would be every other language not named 'PHP'), but of actual, substantiated reasons why PHP is bad, and the other language isn't. And for clarification, saying things like "it's missing some random function that's only the right choice in some specific cases" is an awful reason IMO.
PHP 5.4.0 released
Posted Mar 2, 2012 22:22 UTC (Fri) by khim (subscriber, #9252)
[Link]
It was discussed manytimes. PHP is completely build around violation of Rule of Repair - that's what makes it “suitable for non-developers” and that some thing also means it's turing tarpit.
It's much easier to create half-working prototype in PHP, but to create production-quality code you need not only fight the task at hand but you need to somehow curb this insane tendency to “help you”… by adding security holes to perfectly valid algorithm.
Think about it: how many things may fail if the result of sort() is not, in fact, sorted? Regular expressions are pretty fundamental - yet PHP screws them, too. And so on.
PHP 5.4.0 released
Posted Mar 3, 2012 0:03 UTC (Sat) by rfunk (subscriber, #4054)
[Link]
It's funny, I dislike PHP too, but I'm very familiar with it and use it all the time (imposed for reasons I mentioned elsewhere). And while I can think of many stupid things about PHP, the things you mention would be at the bottom of the list at most, and in some cases I don't even see them.
- Rule of Repair violation. The only place I really see this is in the fact that it's a loosely-typed (and dynamically-typed) language with implicit conversion. While these attributes certainly annoy programmers used to a different type of language, there's nothing inherently wrong with them.
- Turing tarpit. Not even close; in fact it's more of a kitchen-sink language, with everything thrown in with little regard to consistency.
- "help you by adding security holes". Very true, but most of this can be avoided with proper php.ini configuration (though the existence of such a thing is itself a big problem) combined with a "good parts" approach to the language. This is where a novice really causes havoc with PHP, and why I cringe at its common "non-programmer" uses.
- Regular expressions. OK, so they don't perform as well as they could. So what? If you want performance you're looking in the wrong place anyway, and if you're coming from Perl and want a little more speed you just need to use regexes a little less.
All that said, I do think PHP deserves quite a bit of ridicule. It's the most wildly inconsistent language I've ever seen taken seriously, didn't gain anonymous functions (sorta) until the last major release (despite having array-transformation functions that need that sort of thing), and only now is getting a sane array syntax. My years doing Ruby instead were great (except for deployment/sysadmin), and these days I'm much happier when I can do Javascript (including some server-side) than when I'm doing PHP.
PHP 5.4.0 released
Posted Mar 3, 2012 1:00 UTC (Sat) by elanthis (guest, #6227)
[Link]
> Rule of Repair violation. The only place I really see this is in the fact that it's a loosely-typed (and dynamically-typed) language with implicit conversion. While these attributes certainly annoy programmers used to a different type of language, there's nothing inherently wrong with them.
1) Identifiers magically turn into strings, mostly I believe because function handlers have just been strings until relatively recently.
echo FOO; // prints FOO
2) Magic quotes. Yes, they're finally gone, but the fact that some dork put them in there in the first place proves that said dork had no business designing, implementing, distributing, and promoting a language.
PHP 5.4.0 released
Posted Mar 3, 2012 14:56 UTC (Sat) by rfunk (subscriber, #4054)
[Link]
Ah yes, #1 is probably PHP's worst remaining sin. Luckily I don't encounter it a lot, but it did bite me not too long ago.
I loosely put magic quotes in the "help you by adding security holes" category. I'm glad they're finally gone, but I agree that their existence says nothing good about the language designer, or at least the language's aspirations beyond "Personal Home Pages".
PHP 5.4.0 released
Posted Mar 3, 2012 2:42 UTC (Sat) by HelloWorld (guest, #56129)
[Link]
These things have been discussed over and over again, there's no point in repeating these arguments here.
But please, answer me one question: what is PHP actually better at than the alternatives I've pointed out? Because I can't think of anything.
PHP 5.4.0 released
Posted Mar 3, 2012 11:19 UTC (Sat) by ggiunta (guest, #30983)
[Link]
PHP is not a comp-sci guru language. It's an engineer's language.
1. It's easy
2. It's powerful
3. It's fast enough for most tasks
About 1:
Developers moaned about language inconsistencies since about forever, but the fact is that this is not a big problem as some think it is.
Q: Is it find(haystack, needle), or find(needle, haystack)? A: I do not care. I can not remember syntax of all functions in the language anyway, not to mention frameworks, but the online documentation for that function is one click away. And if I'm using an IDE, I get a tooltip to tell me.
I can pick up most php libraries / frameworks out there, plug them in my app, and if I find a problem debug it and patch it in half an hour. This might be true for other languages, but definitely not Java or Perl.
Loose typing is actually a good choice 99% of the time when writing an app. When writing a framework/library it's probably the opposite. But how many developers are writing apps compared to frameworks?
Think about the function validatePassword(string $p1, string $p2) versus validatePassword($username, $password)
. Which one is typesafe? Which one is gonna be abused by the caller?
Heck, even the choice not to have private/protected/public members in classes (for php4) really makes sense in the context of an application. How many times are you going to subclass a class which is specific to the business-logic problem at hand? If you're not going to subclass, all the time you spend thinking about this particular aspect is wasted.
Making the language clean up for yourself at the end of every web page means that things like global variables, generally despised in other languages, are not a bad practice anymore. Purists yell when they see it, but it's only because they have not yet understood the scoping implication of the one-page-one-scrip approach.
About 2:
Want to hack a bit of script in an html page? super fast.
Want to code purely oop? can be done.
Like lambdas and closure? Can be done too (ok, not the best implementation out there, but still...)
About 3:
I like my hashes to be as simple as arrays. I rarely mix them up - depending on context (or the value of the variable at hand) I can figure out which one of the two is in use. So my array construct is slower than in any other known language. Thing is, for making websites the page speed is nowadays wasted mostly 1-in frontend rendering of all the js and css, and 2-in the db query or nosql fetch. Array manipulation is gonna be 0.1% of it.
PHP 5.4.0 released
Posted Mar 4, 2012 1:57 UTC (Sun) by tialaramex (subscriber, #21167)
[Link]
Whatever it is, it's not for engineers. Engineers care about maintenance, and PHP isn't maintainable.
PHP encourages spaghetti, encourages bad practices like using string concatenation instead of parameter binding, even encourages the "copy paste" approach to code-reuse. And so on through a litany of maintenance-hostile behaviours.
It has taken long painful years to beat the worst security mis-features out of PHP. It may be decades before the knock-on effects reach the many PHP "applications" (if piles of accumulated PHP may be so-called) that have grown up while such mis-features existed.
PHP 5.4.0 released
Posted Mar 4, 2012 12:59 UTC (Sun) by DG (subscriber, #16978)
[Link]
PHP is maintainable - if you set about it in the right way using good software engineering practices - code style guidelines, unit tests, reviews, CI etc.
I'm not sure why you think PHP encourages copy+paste coding more than any other language. If it does, it's probably because of it's low barrier to entry which results in some less skilled/proficient people writing it.
PHP 5.4.0 released
Posted Mar 4, 2012 15:41 UTC (Sun) by anselm (subscriber, #2796)
[Link]
PHP is maintainable - if you set about it in the right way using good software engineering practices - code style guidelines, unit tests, reviews, CI etc.
Anything is maintainable if you're investing enough care and effort. People are maintaining large assembly language programs, after all. The real question is whether maintaining something in PHP or assembly language is worth the trouble when there are lots of other approaches that let you achieve the same level of maintainability with less effort (while probably also improving all sorts of other quality metrics to boot). In the case of assembly language, most people have figured out for themselves what they prefer, which is why there are much fewer large assembly language programs around than there used to be.
Having said that, PHP is great. It is the best thing since the invention of sliced bread. Everybody should be using PHP all the time. It would make us Django people look so much more competent and efficient by comparison.
PHP 5.4.0 released
Posted Mar 4, 2012 17:45 UTC (Sun) by man_ls (subscriber, #15091)
[Link]
IME proper engineering is not harder to do in PHP than in other languages; and some things like, you know, serving web pages is actually easier. I have not worked with Python or Ruby frameworks though; only with Java frameworks which grow more byzantine by the year. But people are even suggesting Scala here, so I guess their tolerance for the bizarre must be quite high.
PHP 5.4.0 released
Posted Mar 4, 2012 16:26 UTC (Sun) by HelloWorld (guest, #56129)
[Link]
About 1: PHP isn't easier than Python. And no, weak typing is *not* a good idea, ever. It only makes things easier that are trivial to begin with, in the best case you save a few casts here and there. On the other hand, it encourages people to write code that'll work just fine as long as the input is what the programmer expected it to be, and fail catastropically when it's not.
About 2: embedding Python (or Ruby or Perl) is trivial using modules such as Spyce. And of course, Python has had lambdas, closures and proper OOP for way longer than PHP.
About 3: there's no sensible reason for mixing up arrays with dictionaries, they're simply different things. That doesn't imply that one is harder to use than the other (as can be seen in Python).
So sorry, but I don't buy those arguments. IMO, PHP does nothing better than the alternatives I've listed, and you haven't proven otherwise.
PHP 5.4.0 released
Posted Mar 5, 2012 9:07 UTC (Mon) by ggiunta (guest, #30983)
[Link]
And you have not proven in any way that "all the alternatives" you mentioned above are better than php, either - esp. Perl...
But to each its own, I guess
PHP 5.4.0 released
Posted Mar 5, 2012 12:40 UTC (Mon) by HelloWorld (guest, #56129)
[Link]
> And you have not proven in any way that "all the alternatives" you mentioned above are better than php, either - esp. Perl...
Perl has had *everything* for years that is "new" in PHP 5.4. Same thing with the 5.3 release. Plus it has proper Unicode support which PHP lacks to this day.
Also, I am not the one who started this discussion by asserting random stuff like PHP being irreplaceable, Kit is the one who should explain why he things this is so.
PHP 5.4.0 released
Posted Mar 8, 2012 18:01 UTC (Thu) by sorpigal (subscriber, #36106)
[Link]
So what language is actually better suited for the job that PHP is used for all the time
Perl is better.
But Perl by itself is an incomplete solution. Almost all competing 'better' languages are incomplete solutions compared to PHP. Today I would advocate Mojolicious::Lite as a Perl-based simple PHP alternative.
It allows the 'developer' to write in one file the template and the code and it makes viewing the result in a web browser equally trivial.
And I'm viewing and editing my one-page quick and dirty web site. Initially it's slightly more trouble than PHP for vastly superior results, making it very nearly as good for the ignorant beginner.
PHP 5.4.0 released
Posted Mar 9, 2012 1:25 UTC (Fri) by Cyberax (✭ supporter ✭, #52523)
[Link]
That's it. You get a site with support for localization, specialized admin interface, a decent built-in ORM, etc.
PHP 5.4.0 released
Posted Mar 9, 2012 22:56 UTC (Fri) by sorpigal (subscriber, #36106)
[Link]
Right, same idea: Good language plus framework almost trumps php's low barrier to entry at a much higher quality.
PHP 5.4.0 released
Posted Mar 12, 2012 21:54 UTC (Mon) by dmarti (subscriber, #11625)
[Link]
Yes, the development server is extremely easy, but actually deploying means getting into the finer points of WSGI and either making your own distro-level packages for your dependencies or setting up virtualenv. (Still trying to figure out why all my Django application's static files are 404 when I go through Apache but work fine with "runserver".) Once you get into Django, the actual application code is way cleaner, and the ORM is fine, but PHP's deployment model is easier to get started with.
PHP 5.4.0 released
Posted Mar 2, 2012 17:58 UTC (Fri) by tjc (subscriber, #137)
[Link]
the two big php bugs are still open:
1. it exists
2. people use it
0 2 4 6 8 10
/
/
/
/
/
/
/
TROLL-O-METER
PHP 5.4.0 released
Posted Mar 2, 2012 22:46 UTC (Fri) by Cyberax (✭ supporter ✭, #52523)
[Link]
Troll but true.
PHP 5.3 EOL
Posted Mar 2, 2012 8:42 UTC (Fri) by cdamian (subscriber, #1271)
[Link]
Does anyone know the end of life date for PHP 5.3 ?
PHP 5.3 EOL
Posted Mar 2, 2012 17:33 UTC (Fri) by jmalcolm (guest, #8876)
[Link]
I do not believe that one has been announced. It may be a while yet.
5.3 was released in June 2009 but 5.2 EOL was not announced until December 2010.
PHP love/hate relationship
Posted Mar 2, 2012 14:20 UTC (Fri) by dskoll (subscriber, #1630)
[Link]
I work with PHP every day. It's a horrible language in many ways, but it's so easy to get started quickly and deploy that I still use it.
PHP makes it really easy for novices to write grotesque software chock-full of security flaws. On the other hand, in the hands of skilled developers you can get really nice stuff like Drupal.
PHP 5.4.0 released
Posted Mar 2, 2012 20:19 UTC (Fri) by ibukanov (subscriber, #3942)
[Link]
Last year I discovered that it is much easier to isolate multiple virtual hosts from each other and from the web server with PHP than with Python or Perl. This comes from fast and reliable support for FastCGI that allows to run PHP code that was not created with FastCGI in mind in the first place. So with PHP I can run single lighttpd to serve static pages for all virtual hosts yet in the same time I can run PHP code on per-virtual host user accounts without performance loss.
With Python or Perl running a typical application over FastCGI requires either often significant tweaks or just switching to the standard CGI with corresponding performance loss.
So it is nice to see "Improved CGI/FastCGI SAPI" in the change log for PHP 5.4.0.
PHP 5.4.0 released
Posted Mar 3, 2012 0:42 UTC (Sat) by pboddie (subscriber, #50784)
[Link]
I didn't think anyone used FastCGI any more, but I guess the Web 2.0 brigade has revived the technology. My impression was that the Python community would rather you used WSGI, and before that, even things like mod_python (which got a certain amount of unfair criticism given the benefits it offered) were favoured over FastCGI.
The last time I recall any prominent mention of FastCGI in the Python Web scene was back in the days of Zope 1.x with a brief note mentioning that it was unreliable and not really recommended. I stopped following such matters closely several years later (and thus several years ago) and FastCGI's reputation hadn't exactly improved over that time, but it's possible that it has returned in the caching-front-end-intensive Web architectures of today.
With regard to running Python Web applications in long-running process servers, it should be sufficient for those servers to support WSGI as the API for applications. Then, there shouldn't be any portability issues with regard to deployment in a range of environments.
PHP 5.4.0 released
Posted Mar 3, 2012 1:16 UTC (Sat) by Cyberax (✭ supporter ✭, #52523)
[Link]
Hm?
FastCGI is a nice interface, not bad at all for high-load services. It's just that WSGI is little more 'pythonic'.
PHP 5.4.0 released
Posted Mar 5, 2012 10:41 UTC (Mon) by pboddie (subscriber, #50784)
[Link]
I guess it had something to do with the robustness of the FastCGI implementations back in the day, then. As for portability, switching server technologies shouldn't be an issue: most frameworks support WSGI, and most server adapters expose WSGI. Five years ago or so it was completely possible to write portable Python Web applications - I even wrote a framework for doing just that, pre-WSGI - but if you decided to just write code for, say, Django, I'm pretty sure the deployment opportunities based on WSGI are good enough.
PHP 5.4.0 released
Posted Mar 3, 2012 11:42 UTC (Sat) by ibukanov (subscriber, #3942)
[Link]
If one consider alternatives for apache like lighttpd or nginx, then FastCGI comes naturally. I was surprised how easy it was to run WordPress, FluxBB and custom PHP applications over FastCGI with lighttppd each under its own user account while consuming much less resources than the same applications running under the same account as the apache server.
With Python and Perl that required much more efforts if the application is written with mod_python/mod_perl in mind.
PHP 5.4.0 released
Posted Mar 4, 2012 10:18 UTC (Sun) by niner (subscriber, #26151)
[Link]
With Perl you use frameworks like Catalyst, Dancer or Mojolicuous to write web applications and with them you can switch from mod_perl to fastcgi and vice versa without changing a single line of code. In addition, you get an integrated development webserver and support for running over plain old CGI and it's trivial to scale up by serving static files with a different server like ngnix or lighttpd.
It cannot possibly get easier than that.
PHP 5.4.0 released
Posted Mar 4, 2012 11:15 UTC (Sun) by ibukanov (subscriber, #3942)
[Link]
> With Perl you use frameworks
The problem starts when it is necessary to quickly port to FastCGI badly written and unmaintained scripts that are not written using those frameworks. With PHP it just works with default settings. With Perl it requires to manually fix those. So despite all its limitations and ugliness PHP was a winner in my case due to universality of its default configuration.