The New PHP 254
An anonymous reader writes "This article at O'Reilly Programming suggests that PHP, a language known as much for its weaknesses as its strengths, has made steady progress over the past few years in fixing its problems. From the article: 'A few years ago, PHP had several large frameworks (e.g. CakePHP, CodeIgniter, and so on). Each framework was an island and provided its own implementation of features commonly found in other frameworks. Unfortunately, these insular implementations were likely not compatible with each other and forced developers to lock themselves in with a specific framework for a given project. Today the story is different. The new PHP community uses package management and component libraries to mix and match the best available tools. ... There are also exciting things happening with PHP under the hood, too. The PHP Zend Engine recently introduced memory usage optimizations. The memory usage in PHP 5.5 is far less than earlier versions.'"
Wake me they fix namespaces (Score:4, Insightful)
It is nice to see that PHP is starting to grow up a little bit. They have long way to go.
Re: (Score:2)
Re: (Score:2)
Wake up time. PHP actually has a pretty decent way to remove "garbage". First they make the compiler (and documentation) warn you about a feature being made obsolete in a future version, and then a few versions later they do remove the feature.
Here is an example (quote from the manual [php.net]):
As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal
Re: (Score:2)
Re: (Score:2)
Every time you break existing applications, you create systms that are stuck with old and buggy versions. That's bad enough normally, but is a terrible idea in a language meant for writing Internet-facing apps. Dealing with detritus is preferable to burning down the house to get rid of it.
One question (Score:2)
Have they managed to keep from breaking crypt() recently?
Re:One question (Score:5, Informative)
yeah - http://php.net/password_hash [php.net]
It's now pretty easy to do password hashing correctly.
Re: (Score:3)
Re: (Score:2)
That's, er, function hashing - http://news.php.net/php.intern... [php.net]
Perl vs PHP (Score:4, Interesting)
Being long in the tooth I do all my web development via Perl using my own nice call back templating engine and of course CGI.pm. Nice separation of code and html -neither of the two find themselves in the same file. Once in a while I have to do some repair work for customers in PHP and in horror find the html and code mixed to together with wild abandon and massive uses of global variable and I wonder PHP is so darn popular.
Re: (Score:3)
I've found that using the Smarty [wikipedia.org] template enginr helps me avoid that situation in PHP and the learning curve is fairly shallow.
Re: (Score:2)
Having seen some Perl web scripts that very much do not meet this description, and some PHP that was nicely templated I can say with confidence that it is not the language that is at fault here.
Re: (Score:2)
Wow - I'm not sure you should be using the sample of bad existing code as an argument against PHP and FOR perl. Yikes.
Why use the Zend engine at all? (Score:4, Interesting)
Many of the problems with PHP are from the crappy language implementation. I recently came across a Java implementation of the language. It's been around forever, but as I hadn't heard of it, I figure many people reading this thread haven't either. It's Quercus [caucho.com]. It's certainly worth a look as a Zend alternative.
Re: (Score:2)
> Many of the problems with PHP are from the crappy language implementation.
Yes, because switching to a subtly different language implementation is not going to cause any problems running code that was written for the standard PHP implementation.
> It's Quercus [caucho.com]. It's certainly worth a look as a Zend alternative.
That was release 7 years ago. No one appears to really use it.
Do you really think that if it was such a great improvement over the Zend engine that people wouldn't be using it?
Still waiting (Score:4, Interesting)
I'm still waiting for PHP to be completely case sensitive, a sane scoping scheme and real object oriented (can you say polymorphism)
Re: (Score:2)
PHP already has case sensitive variable names. $Foo and $foo are always different variables.
Function names, class names, keywords (class, function, extends, if, while, etc) are always case insensitive.
However, constants are sometimes case sensitive, depending on their declaration.
I do a lot of PHP development, but these days it's only sane by the fact that I've been doing it so long I understand many of it's weirdness. Also, using frameworks (Symfony 1 & 2) and finally using a template engine (Twig)
register_globals (Score:2)
The beautiful thing is their lovely page explaining that it wasn't an insecure design, just one which "could be misused".
I'd say that a feature that easy to "misuse" in ways that lead to security holes is, in fact, a pretty good example of an "insecure design".
A fractal of bad design. (Score:5, Insightful)
I don't normally like linking to blog posts, but this one pretty much sums up PHP for me:
http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/
His analogy is very apt.
Moving to Python (Score:5, Informative)
It is shaping up to be one of these things where my only regret is not switching sooner.
I was a huge defender of PHP for a long time but that time is over. There are interesting things like HHVM that are another bandaid for PHP but I am sick of making PHP work. I am sick of typing all those stupid dollar signs. I'll just say what so many have said before, "Python is like typing pseudo code, except you are actually coding." I don't look at my python and shudder.
PHP reminds me of some of my own projects where I changed course many times leaving strange little architectures and changes in philosophy. The longer the project goes on and the more it changes direction the more debris it leaves behind. It is not necessarily broken just sort of all just off.
Where Python is a tiny problem with the web is that setting up a development environment took me a tiny bit more work than the usual LAMP setup. This might make it harder for beginners but maybe that is a good thing. I don't mind leaving the beginners back in PHP land.
It's still unmaintainable crap (Score:2)
PHP's biggest problem is lack of modularization and encouragement of inline script hacking. It suffers from SQL that lacks proper commit controls. Implementations I've used leak connections like a seive, forcing restarts of the database servers on a regular basis.
Bottom line: PHP is the one tool I've used that I hate more than JavaScript. JS is functional elegance compared to PHP spaghetti.
Re: (Score:3)
> It suffers from SQL that lacks proper commit controls.
Wat?
> Implementations I've used leak connections like a seive, forcing restarts of the database servers on a regular basis.
While that must have been frustrating for you - that's not a common complaint, so was probably specific to either your DB or configuration.
> PHP's biggest problem is lack of modularization and encouragement of inline script hacking.
You mean you suck at writing decent code, without being forced to do things 'properly' ?
Re: (Score:2)
No, it means people keep demanding that I work on PHP I didn't create and it's all steaming piles of SHIT.
Like PERL, you can create maintainable and readable PHP. Most people don't. They hack something together thinking they'll need it for a month and be done with it, and the steaming turd keeps on in production for years afterwards.
And then some poor fellow like yours truly is expected to enhance the god damned thing which has no comments, uses perverse libraries that no one else uses and which have
Re: (Score:2)
My response to those demands nowadays?
"Yes, I know PHP. That's why I won't work with it. You couldn't pay me enough to take on a PHP project."
Re: (Score:2)
The only time I've seen this was when a "Java Expert" built out a platform using PHP, and tried to make it jump through hoops to work like Java. Net result? Factory factory factories (not exaggerating) that resulted to an amazing kludge of massive memory-hogging threads which brought the servers down on a 2-3 hour cycle. Took massive refactoring to clean up that mess.
A scripted language funda
Re: (Score:3)
The fellow who wrote the original code used a library I'd never heard of for MySQL connectivity. They didn't know how to use SQL properly. They didn't know how to error check results. Hell, they didn't even know how to sort data for the users as they'd been asking him to for months before.
But no, he left the company and the steaming pile of crud was dropped in my lap to fix.
By the time I was done stabilizing the thing, there must have been a whole 10% of the original code left.
Just because it's po
PHPs badness is its advantage. (Score:5, Interesting)
I love Python, I think JavaScript is sort of OK and I did a lot of serious programming in ActionScript 2&3, both of which are quite simular to JS. I was basically forced into doing PHP by the market. I never really liked PHP but I really never hated it either. The thing about PHP is that it's so specific in its domain and such a hack that no one doing PHP development for a living will go around boasting about the greatness of the language. There is a refreshing lack of arrogance in the PHP community which, in my observation, makes it very easy for n00bs to pick up. As a result we get countless people reinventing the wheel in PHP and discovering basic programming patters anew for them selves and starting yet another Framework/CMS/Whatnot and the results often are really bizar. But the community remains alive that way.
F.I. I'm working myself into Drupal at my current employer because it's the prime go-to CMS here. It's like a live alice in wonderland trip. A strange historically grown mess, barely tamed by sanitiy and a relentless chaotic community that all by accident seem to come up with hacks that somehow solve the problem in some way. And yet there's a solid global corporation building its business all around Drupal [acquia.com]. The surreal hacks with which the Drupal people solve their problems are mindboggling, and yet everybody seems totally OK with it. And Drupals track record of deployments is impressive.
I guess with PHP it's somehow like the C vs. Lisp argument: C is so shitty compared to Lisp that you have to get yourself together and work as a team, or you won't get anything done. Hence Lisp has this loner exisitance on the side and all the real work gets done in this ancient C thing.
PHP is a simular thing. It is so bad that no respectable programmer would pick it up voluntarly nowadays, but yet it grew out of Perl (which is worse in some ways), was somewhat of an improvement and was at the right place at the right time. The badness of PHP accounts for its considerable lack of arrogance (compare the PHP community to the Ruby community for instance) and for no one feeling guilty when he does a quick bad hack.
As a programmer you don't feel dirty when you do bad programming in PHP, you already felt that when you picked PHP as the solution. Hence quite a bit of work gets done in PHP. That's why PHP has Drupal and Typo3 and Joomla and the Java Community has nothing of that proportions. The barrier of entry into PHP is *very* low which gives it its momentum.
My 2 cents.
Re:Too Little, Too Late & MtGox (Score:5, Insightful)
Why in 2014, do I have to decorate variables with '$'?
That is your first complaint about PHP? That? I can't stand PHP but, seriously, that is first on your list of PHP badness?
Re:Too Little, Too Late & MtGox (Score:5, Insightful)
Especially since it's actually one of the only things that makes PHP (barely) readable.
Re: (Score:2)
In an object oriented language, as PHP attempts to be, $ is a stupid idea, just like decorating variables with types, like bInstalled (bool installed) it iMaxLength. It's not such a bad idea in JavaScript though, where anything goes.
Re: (Score:2)
Hello, JavaScript is object-oriented. This is because, in JavaScript, everything is an object. Period. Loose typing and prototype inheritance do not alter this fact.
And you do not need to decorate your variable names with anything in JS.
Returning to the topic: Back in the day, PHP was sort of awesome for those of us who weren't C or Perl gurus, but those times have passed.
Today I don't use it for anything other than the occasional shell script and simple websites that do not involve the transfer of goods, f
Re: (Score:2)
Why in 2014, do I have to decorate variables with '$'?
That is your first complaint about PHP? That? I can't stand PHP but, seriously, that is first on your list of PHP badness?
Maybe he is poor and seeing all those dollar signs depresses him.
Re: (Score:2)
If you can't tell the difference between GET, POST and COOKIE you have bigger problems.
You complain about that but you suggest Node? Node is fine, but pulling out request variables requires you to parse through the headers and query string.
Further more, sanitizing DB inputs and making sure your logic doesn't suck isn't the worst thing you have to do. Mt.Gox went down because their API was stupid, not because of some fundamental flaw in PHP.
I don't know. php is the Gary busey of programming languages. Used t
Re: (Score:3, Insightful)
I used to think there weren't plain bad languages. Now with more experience under my belt, I know better.
Every language has quirks. You get used to them, and do what you need to do. PHP is almost nothing but quirks. The only languages I can think of worse than PHP are those deliberately designed to be bad: Brainfuck, Malbolge, INTERCAL, and the like. I'm not even sure that some of those are worse than PHP.
The entire structure and implementation of PHP screams of hasty decisions by cowboy coders who just dec
Re: (Score:2)
Rasmus Lerdorf told me at a con some years ago that he was still amazed at how PHP had taken off: "It was just a hack so I could get some things done, and still, that is all it is now, really."
Re: (Score:2)
You might not be aware of PHP in the old days, but they used to move all the variables into the script so that
$_GET['x'] and $_POST['y']
would be $x and $y... ("register globals") So yeah, you couldn't tell where they came from. The situation with $_* greatly improved things especially when they deprecated register globals.
Re: (Score:2)
register_globals hasn't been part of the default PHP runtime since 2002.
see: http://www.php.net/ChangeLog-4... [php.net]
There are a lot of WTFs to PHP, something that hasn't been true since the first Bush administration isn't one of them.
Re: (Score:2)
And there used to be an import_request_variables() function that would allow you to define which request vars (get, post, cookie) you wanted and a prefix for them.
import_request_variables("rvar_","p");
Would make
$_POST['foo']==$rvar_foo
Re: (Score:3)
You never should have to sanitize your db inputs. Why? Because then you have to always unsantize them, else you end up with a crap string because it isn't escaped/unescaped enough times. The right thing to do is to use the database driver's bind interface. Basically, your DB values should be treated as opaque blobs as far as entry and retrieval go. Now if you need to verify a date, that's another matter. But you should be treating them as opaque blobs, full of nulls, quotes, semicolons and unprintable chara
Re: (Score:2)
You mean like PDO? [php.net]
By sanitize, I mean, don't just write, "INSERT INTO table (col1, col2, col3, col4) VALUES ($unescapedValue, $hosed, $haxedLol, $bobbyTables)".
Which you can totally do in Ruby, Python, C#, NodeJS, etc.
I know mysql_real_escape_string is kind of a pain in the ass. Not to mention a huge WTF. Is the other one fake or something? Still, it's not perfect, but can you do Real Work in it? YES. It's not MUMPS for god's sake.
Re: (Score:2)
Don't you mean "mysqli_real_escape_string?"
http://us3.php.net/mysql_real_... [php.net]
I kinda liked PHP but this stuff started to annoy me. Not only are these methods database specific, but there are tons of deprecated functions in PHP. Sure it's usable - but it's very easy to use functions you're "just not supposed to." Though perhaps that's something they're trying to change as well?
Re: (Score:2)
They're driver dependent. If you don't want the mysqli set of methods, don't enable the driver.
Re: (Score:2, Insightful)
The very fact that several websites exist to document inconsistencies in the language implementation should make you wary.
Where do you find compiler devs who manage to evaluate 0x0+2 to 4?
The fact that there is a function called real_escape_string scares the shit out my me, because it implies there exists a function called escape_string which doesn't really escape strings.
Re:Too Little, Too Late & MtGox (Score:4, Insightful)
That reminds me of people who call a document "x_final", but then change their mind and so create a second one called "x_final_final", and change their mind again to get "x_really_final_this_time_I_promise". I suggest version numbers, but then they say, "But version numbers don't tell me which one is final". I gave up on them.
Re: (Score:2)
I suggest version numbers, but then they say, "But version numbers don't tell me which one is final". I gave up on them.
I work daily with a codebase full of methods like connect_v1(), connect_v2(), connect_v3(), ... .
You do *not* want to go there. Please trust me on this.
Re: (Score:2)
Why in 2014, do I have to decorate variables with '$'?
Well for one thing effortless string interpolation... and it nicely identifies what is a scalar
Re:Too Little, Too Late & MtGox (Score:5, Insightful)
I do a lot of coding in PHP, and there's a lot of things I don't like about it, but your particular dislikes don't make a lot of sense.
Why in 2014, do I have to decorate variables with '$'?
It's not like PHP was written in 1965 and thus there was some hardware (memory footprint, compilation speed, etc) reason variables are prefixed with a dollar sign. It was a design choice. That's so you can do this:
$count=5;
echo "The total is $count.";
And you can use the same variable syntax in your code as in strings that are automatically parsed.
Why is the assiciative array syntax take two characters that look a comparison operator?
It doesn't "look" like a comparison operator if you actually know what the operators are. <= and >= are comparison operators, and => is not a comparison operator in any language I've ever used. A single equal sign looks like a comparison operator too, and woe to the developer that doesn't have the universal C-like basic operators (used in dozens of modern languages) memorized backwards and forwards.
Why do I need == and ===?
For the same reason that Javascript and other scripting languages need it. Those languages do automatic type conversion, and sometimes you don't want that to occur. The alternative is manually casting things, which isn't very script-like at all, and having to explicitly deal with types is more like C than an "easy to use" scripting language. Thus there are two equality operators for the times you don't really want 0 to equal null to equal false.
This one is even more ironic considering Javascript based node.js is your favorite server side platform, and thus you would also have to use both == and === operators in your preferred language anyway.
ANd vaiable confusion between $_GET, $_POST and $_COOKIE
I don't even know where to begin on this one. They are 3 entirely different things, with the most self-explanatory names I can think of. That's exactly as it should be. Look at $_REQUEST if it's too difficult to figure out which you should be using (and woe to your client if that's the case).
Re: (Score:2)
It's that same easy substitution, i.e. $sql = "SELECT fname, lname from people where id='$id'" that leads to data breaches. [xkcd.com]
Re: (Score:3)
Like making it more difficult syntactically prevents SQL injection attacks either:
var sql="SELECT fname, lname from people where id='"+id+"'";
Same vulnerability in Javascript.
Re:Too Little, Too Late & MtGox (Score:5, Insightful)
In PHP this is now solved with parameterized queries. Plus any framework or CMS worth it's salt was doing it already:
$sql = $dbConnection->prepare("SELECT fname, lname FROM people WHERE id = ?");
$sql->bind_param('s', $id);
$sql->execute();
If you're rolling your own DB connection layer in modern PHP, you're doing it wrong.
Re: (Score:2)
The real issue is there's too many PHP shitheads out there still doing it wrong.
What I don't get is why the PHP shitheads don't use a framework. I am a PHP shithead so I use Drupal. I know I don't know a lot of PHP. I don't want to. But I wanted something I could conveniently host anywhere and I've got it.
Lousy coders will be lousy coders (Score:4, Insightful)
And how is this different from "SELECT yada yada " . id . " yada yada"
How exactly does ANY language that allows catenation not allow you to enable sql injection attacks?
"Coders" like you want a language to protect you from being stupid because you are stupid. It is your kind that insists everything be made child proof because you are a child yourself.
Re: (Score:2)
There's another (minor) reason to prefix variables with $: That way you can use "reserved" words as variable or field names, say $class, $abstract, etc.
Re: (Score:2)
You complain about == and === in PHP, but then you bring up a javascript solution (Node.js) as an alternative. This leads me to believe that if *you* decided to rewrite Mt Gox using your beloved Node, another hacker would probably get rich pretty soon. And just as it happened with the PHP version of Mt Gox, the problem would lie in the implementation not in the language.
Re: (Score:2)
Why do I need == and ===?...........My favorite two are Node[JS]
Uh........there's something you need to know about Javascript..........
Re: (Score:2)
Why in 2014, do I have to decorate variables with '$'?
Not a big fan of variable interpolation, I'm guessing?
Why is the assiciative array syntax take two characters that look a comparison operator?
Don't forget to ask Perl the same question.
Why do I need == and ===?
Because the language is loosely typed. There are other loosely-typed scripting languages that have both of these operators as well.
ANd vaiable confusion between $_GET, $_POST and $_COOKIE
So you would prefer to have them all in one array? Or as global scalars?
Seems to me you're complaining about PHP because it's a scripting language and not C or Java.
Here's a suggestion for you: If you don't like the syntax, or if you want strict typing, use something else. If you don
the real horror of MtGox (Score:3)
Sure, some people lost some bitcoins. But what are those?!?!? Intangible sets of numbers and letters that don't exist in the real world. Not to be insensitive, but boo-hoo!
The bigger tragedy here is that the MtGox site had a vulnerability that has probably been exploited for more than a decade by some nefarious organization to steal peoples' Magic The Gathering Card
Re:6 scripts at once? HNNNNNNNNNG (Score:4)
Yeah. Stupid global weather simulations also run like a dog on the Pi.
When will people start testing their complex simulations on multiple platforms?
Re: (Score:2)
if ($filehandle = fopen($filepath, 'rb')) {
$filecontent = fread($filehandle, $filesize);
$filecontent = base64_encode($filecontent);
$filecontent = 'data:image/' . $filetype . ';base64,' . $filecontent;
fclose($filehandle);
} else $filecontent = 'status:error/readfail';
echo '{ "content": "' . $filecontent . '" }';
}
Each 6 requests comes with about two seconds of lag where the system needs to take a dump because it's so confus
Re: (Score:2)
Try:
if ($_GET['do'] == 'read' && file_exists($filepath))
echo json_encode(array('content' => 'data:image/'.$filetype.';base64,'.base64_encode(file_get_contents($filepath))));
The key bit being file_get_contents. It is a hell of a lot better than using the f functions except for very specific circumstances.
Also check the ram usage on the Pi. It should be able to keep a few 8kb files in the file cache.
Re: (Score:2)
I've never experienced a binary safeness issue in PHP for some time. The usual stuff I do like file_get_contents, substr, strlen, etc... are all binary safe.
Not sure what you're talking about (Score:2, Interesting)
PHP works, it's fast as heck, and I can do anything you can do in python/perl just as well and way faster. My host for my hobby site (Shameless Plug [glimmersoft.com]) gives me php and a mysql DB for $7 bucks a month, and that's probably more than I should be paying. If I want perl/python that goes up to $100/mo...
Re: (Score:2)
I'm paying $7.95 per month for a virtual machine, and I don't think that is the cheapest option. If I want to put perl or python on, I can, although last I checked a J2EE server was running into the RAM limits for the VM to do anything non-trivial with it.
Re: (Score:3)
Getting a VM (VPS) is not the same as shared hosting. WIth a VM you have to install, maintain, patch and monitor everything yourself. Obviously cheap providers that offer PHP/MySQL hosting for $3 a month won't offer terrific performance, the resources will be shared with a lot of other customers, but for a simple website with maybe a shopping cart and a small catalog it's far less overhead to use shared hosting than a VM and there is a big market for that.
This being said, there are lots of cheap hosts that
Re: (Score:3)
Re: (Score:3)
"WIth a VM you have to install, maintain, patch and monitor everything yourself"
My experience with shared hosting is that they change system configuration all the time without informing me and thereby breaking my scripts. Never have that problem with a VM, but I admit that setting up a VM with dns, apache tweaks, iptables, and so on, is a major effort for someone who doesn't do that for a living, like me. But after that it's very little maintenance.
By the way, the site in my sig runs on shared hosting, incl
Re:Not sure what you're talking about (Score:5, Insightful)
Re: (Score:3)
"no you cannot do anything in PHP that you can do in Python or Perl!"
that statement in itself is true, but PHP is a web language and as for things to do ON THE WEB yes I would argue it is more feature rich.
Even if you disagree with the Python comparison it certainly beats the current state of Perl all the hell.
Source: I've developed in all three for work.
I've only ever developed in PHP (well, I tried ruby for a few months then ran away screaming in frustration), but I know of things in python/perl that PHP is missing.
For example PHP doesn't begin executing your code until after the browser has sent _all_ of the post data. This makes it impossible to create a file upload progress bar in PHP. You can do it in modern browsers with javascript now, but previously it had to be done server side and only languages like perl can handle that - because they begin exec
Re: (Score:2)
http://www.php.net/manual/en/s... [php.net]
http://pecl.php.net/package/up... [php.net]
Re: (Score:2)
Actually it isn't. Read it again, carefully.
Re: (Score:2)
I've never done my own garbage collection, and PHP just updated it in 5.3 [php.net].
PHP works, it's fast as heck, and I can do anything you can do in python/perl just as well and way faster.
I don't know about python/perl but there are operations in PHP that need 200MB of memory which I could achieve in C with only 20KB of memory.
That's a 10,000x increase in memory consumption for PHP. If this has improved in version 5.5 I can't wait to give it a try.
And it's not just memory consumption, there are times when I run a xhprof on some slow PHP code and find out it's spending 90% of it's time allocating and/or freeing memory. If it used less memory, it would spend less time managing it.
PHP is a grea
Re: (Score:2)
You can get 20 dedicated VPSes for ~$20 a month and run them as a beowulf cluster for all they care.
Yeah right! Beobunnies run faster than that!
Re:Not sure what you're talking about (Score:5, Insightful)
So the sort of people who claim that PHP is worthwhile are those who stick with a terrible webhost and have no clue how much they should be paying?
Yes, that sounds typical.
Actually I think its more that a certain percentage of the population has as the top priority just being able to get something done, and the low level details of this or that's garbage collection and memory management is way, way down the priority list somewhere.
Re: (Score:2)
low level details of this or that's garbage collection and memory management is way, way down the priority list somewhere
Agreed, any memory leaks or performance problems should fall out in testing. The major problem I have with PHP is it's poor backward compatibility with previous versions, that sort-coming can quickly turn into a giant configuration/maintenance headache. Glad to see they are trying to do something about it.
real_foo_bar() and somesuch_improved() (Score:4, Informative)
Make PHP the lauging stock of many a programmer.
The language's development has been in the wrong hands from day one.
You can do great things in Python because of Python.
You can do great things in PHP in spite of PHP.
Re: (Score:2)
I keep saying this on Slashdot: PHP has it's weaknesses, but inconsistent naming conventions isn't a major problem. What made PHP the laughing stock is looking at incompetent coders' code and thinking that's how you do things in PHP.
PHP is a good language for web development. It has an easy learning curve and gives you power to shoot yourself in the foot. Combine those two and you get a bunch of at
Re: (Score:2)
mysql_real_escape_string [php.net] is a wrapper of a C function [mysql.com]. Does that make C the laughing stock for you as well?
Wrapping your house in toilet paper would make your house a laughing stock ... that doesn't mean your house is now though
Re:You don't know what you're talking about. (Score:5, Insightful)
PHP has always used explicit memory management.
allocate_StringMemory()
sys_FreeMemory_UTF8()
Watch out because there is no way to tell if allocation fails. That's convenient though because it makes sys_Free* idempotent; there is no difference between failure to allocate and multiple free-s.
With 5.5 you get a great new function;
sys_FreeEverything() // in traditional mixed camel case + underbar style!
Now you don't need to keep track of allocations and release them. Just blow away all allocations across all requests and start fresh. It's really great for fixing those darn memory leaks.
Re: (Score:2, Insightful)
Bullshit. '=' is assignment in all cases - it is predictable behavior.
However, in php:
"hello" == false is FALSE.
0 == false is TRUE
Therefore, "hello" == 0 should be false. But it doesn't.
"hello" == 0 is TRUE.
I understand WHY it happens. My understand why and when doesn't make it right.
Re: (Score:2)
Re: (Score:2)
Why would anyone ever assume the latter? It's not true for anything but natural numbers (0.5 > 0.3, 0.5 * 0.5 = 0.25 < 0.3).
Re: (Score:2)
Re: (Score:2)
Re:PHP (Score:5, Insightful)
Every common language out there has ugly stuff of one kind or another.
Re:PHP (Score:5, Interesting)
Honestly, BASIC's wins this round just by virtue of being so limited that it's hard to shoot yourself in the foot. I don't count GOTO, as jumps aren't really language specific. Having tutored programming for years, I can say that students are perfectly able to write speghetti code with or without goto.
Re: (Score:2)
you can't write more than four lines of Fortran without painting some Star Trek action figure
I like that. I'm going to use that.
And GOTO is over-villified. In BASIC it is the only sane way to do error handling. In other languages, I frequently use the "continue" operation, which is just a limited goto with a different name.
Re: (Score:2)
As soon as the BASIC ecosystem gets a good templating framework like Twig, a good package management system like Composer or PEAR, convenient SDKs for most cloud providers like AWS or Azure, native support for JSON and easy access to mainstream database drivers (RDBMS and NoSQL), I'm definitely jumping on the BASIC bandwagon!
Seriously, if you compare programming languages based on HelloWorld, it's easy to come out with worthless conclusions such as BASIC > $ANYTHING or $ANYTHING > PHP, but when you ha
Re: (Score:2)
"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
Re: (Score:2)
BASIC is just imperative programming, and I find it similar to simple assembly programs by the way. It gives you understanding of both and doesn't teach much. C is just BASIC with pointers and functions. :) and why just stop at defaming BASIC. All imperative programming is like BASIC, some will argue functional programming should be taught instead.
Today that "seminal article" would be called a rant
Re: (Score:2)
and why just stop at defaming BASIC
He didn't
Re:PHP (Score:4, Insightful)
Python has the whole whitespace deal, Perl code tends to be unkempt
Now this is a great comparison. One language is bad because it enforces tidiness, and the other is bad because it doesn't.
Re: (Score:2)
Re:Inconsistency (Score:4, Insightful)
Cute. In JavaScript: "5"-2 = 0 and "5"+2 = "52". Even PHP isn't *that* nut.
Re: (Score:2)
Re: (Score:2, Informative)
I agree they are incomparable. Javascript is much worse in so many ways...
Re:Inconsistency (Score:4, Interesting)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Until I can get at least a warning on reads to undefined variables I will never use PHP for anything serious again.
Look into ini_set [php.net]. Specifically 'error_reporting'.
Re: (Score:3)
Whereas it should of course be fewer_crabs()