PHP introduces "goto"
php.net
php.net
<?php
wtf:
echo 'For real!?';
echo 'Srsly!?';
goto wtf;
?>
Heh.And why, except perhaps for the hack value, would you simulate a state machine in PHP?
GOTOs are good when used wisely in certain contexts. I don't see where they could be of any use in the PHP niche (but I'd be glad to hear about such examples). Seasoned PHP coders don't need it.
Besides, PHP is mostly a beginner's programming language, who learn by example using code found online. They will be exposed to even worse practices from day one.
But for PHP, which is mostly for web development, I would think using exceptions is a much peer-friendlier way of handling what you'd probably be using goto for in a web app.
If you're writing state machines or parsers, PHP probably isn't the way to go anyway. But hey - whatever floats your boat.
Adding goto just incremented the keyword count, nothing more. Bad coders will still keep on writing bad code, with or without the help of goto.
You can have bad programmers in any language - PHP just has lots of them because it's a popular language, but there is nothing wrong with the language itself.
And, saying, "PHP is not any worse or better than any other language" is saying that all languages are equal. Which, having worked in a number of languages over the years, including PHP, I know to be false. PHP is worse than many languages, and better than many for some classes of problem. It's just silly to say that all languages are equal.
You are confusing the language and the library. And for that matter the library is not bad either, it does however have a few poorly named legacy functions.
> It's just silly to say that all languages are equal.
Sorry, I wasn't really trying to say that. I meant "loosely typed procedural languages" not "any other language".
You pick the language the matches what you are doing, there is nothing inherent about PHP that makes it bad.
A library function that is not optional is effectively a keyword. The PHP standard library (all ~3000 functions) is not optional, as far as I know.
However no one bothers. Why? Because while having lots of keywords is a problem in theory, in the real world it doesn't matter at all.
Right now - what would you change. Keep in mind it's a loosely typed procedural language - that's not going to change.
Given that, what would you change?
False. Not all languages are created equal, and PHP is on the shittier end of the spectrum.
And as I said before, it's a loosely typed procedural language, so don't try to compare it to a functional one. Within that type of language, what's bad about PHP?
The usual technique for evaluating something is to compare it to its competitors, and some of those are functional!
One of the bad things about PHP is that it lacks the higher-order capabilities of most functional languages. It's also inconsistent, easy to write slow code in, makes it easy to introduce massive vulnerabilities, and ugly.
It's 2009. Nobody should be using PHP any more.
And what's ugly about PHP? It looks almost exactly like C.
It is inconsistent (sometimes), but it's not "easy to write slow code in", there is nothing in PHP that makes slow code more or less likely.
It's 2009. Everyone IS using PHP, and almost no one uses functional languages. Oh they get a lot of press, but few deployments.
I'm really tired of these illogical attacks on PHP. No one has ever told me a problem in PHP compared to other procedural languages except that 0 == "" is confusing.
It's always "but everyone knows it's bad". Sure go along with peer pressure if you like, but I prefer to look at reality.
Really? I use the functional capabilities of Python and JavaScript all the time when I use those languages.
And 0 == "" isn't really confusing. You want confusing?
array(0 => false, 1 => true) == array(false => "0", 1.9 => " 0")
The real problem with PHP is there's no simple way to stop it from guessing what you might have wanted when it's utterly wrong.There are so many languages that use a more elegant syntax, reducing the time (and pain) it takes to prevent and find errors, and add functionality.
Given that there can be both well and badly written PHP, other good language choices in general have a consistent and/or clear choice as it comes to syntax (and less keywords to memorize).
Some choices of dynamic, loosely typed languages are:
Ruby, while perl-inspired provides some very pleasant syntax.
While Python is less pretty, there is generally one good way of doing things. Python code is also often consistent across developers, even if its at a mostly superficial level.
PHP is probably more pleasant to work with than ASP/VBScript, but in 2009, with other choices, if you don't have to use PHP and don't mind trying something new, why don't you?
You can write OK code with PHP, but you can't write excellent code.
(And no, I am not implying that code is bad unless you use a lot of anonymous functions. I am just saying that it's an essential tool that you really need when certain situations arise. In PHP, those situations will have to involve hacks.)
You say the "list goes on" - so I googled for a list http://www.tnx.nl/php.html. And half the things on the list aren't even true! And the rest are style choices (more functions with less parameters, or fewer functions with more parameters).
Anyway, if you haven't used these features before, you might not see the need; see the "Blub" essay for details on that.
I disagree. Consider the following PHP:
function inc_all($i, $xs) {
array_map($xs, function($x) use ($i) { return $x + $i; });
}
And compare it to the equivalent in, for instance, Haskell: inc_all i = map (+ i)
Most languages can express the same concepts as PHP, but can do so much more clearly and concisely. The criticism of PHP is deserved: it's a very badly designed language.Every time I ask people what's wrong with PHP they give me answers from functional languages. I've yet to see anyone give me an example from a procedural language.
def inc_all(i, xs)
xs.map { |x| x + i }
endHaskell fits as "any other".
"Haskell is a functional language, PHP is not. So it's not a valid comparison."
So, PHP is not any worse or better than any other language that's just like PHP?
I also disagree, but in the sense that PHP is both better and worse than other languages, depending on your metrics. I feel that talking about code terseness is weird if it takes more effort to actually complete whatever project you're working on (due to lack of libraries, less active community, what have you).
$foo = 42;
$bar = 69;
$which_one = 'foo';
print eval "\$$which_one";What I was referring to is the actual renaming the variables in run-time, i.e. change variables' key in the table of variables. So the code like this:
for ($i = 0; $i < 8; $i++)
{
..
<rename i to j>
..
}
would throw a run-time error on the second iteration, because $i will become undefined. It was completely and utterly "out there", that's why I remembered it. Also showed it to a bunch of people, all of them were equally amazed. But now I can't seem to find where I saw it and what the exact syntax was.So I doubt this will make PHP any worse than it already is. They should really consider adding some useful features, though.
All of this language-ism is killing my chi.
Error handling and portability of code from other languages will make PHP more widely used. That is the goal of the founders/contributors: make PHP used as widely as possible on it's features alone.
I'm all for the "don't protect programmers from themselves" philosophy, until I'm the guy who has to use or maintain the code.
I can finally get rid of some spaghetti code: goto emulation via while loops.
Yes, it's not often you need goto, but sometimes you do.
Its a lowering of basic blocks that I want to print out to test.
What's yours?
This is being said as someone who has created marvelous applications in PHP and has dealt with all the PHP language shortcomings up to this point. Makes me truly, truly sad.
There is also no reason for a developer to use it if it's not wanted.
So long as it's not widely publicized in tutorials and the like, I don't really see a whole lot of novice coders getting their hands on this. I'm not particularly concerned about experienced programmers using GOTO in PHP, especially if they've used in another language where it is more necessary.
gotos are a bad programmer's recursive method. Even people that use while loops like pepper scare me a bit. I have seen many'a'app get stuck in memory draining death loops with goto and even while(). Flags are dead, long live events and messages.
"It is not allowed to jump into a loop or switch statement. A fatal error is issued in such cases."
At least that isn't possible. What a mess it would be if this wasn't the case.
I can't wait to spend minutes of my life when I have to go through another programmer's PHP code who uses gotos.
Welcome to 1980.
While loops limit the scope of variables inside the loop. For C++, that means a variable declared inside cannot be used outside - logical, and OOP.
But PHP has no concept of privacy or scope, even its "rules" may be broken (though not guaranteed to always work) and come out with the right results. Anything will compile, and usually the results are as expected.
So if you have a while loop with no concept of scope or local variables, I guess the restrictions are gone. A number of nested loops with breaks; and continues; all over end so long as the concept of limited data scope/access is not present as in PHP are exactly equivalent to goto as it is.
I guess a language as, shall we say, 'relaxed' as PHP is well-matched with relaxed keywords like goto.
Although, PHP's gotos don't allow they, and PHP still only admits structured control flow.
10 PRINT "WELCOME TO 1980"
20 GOTO 10PHP will never fully be utilized as an OO language by the vast majority of its user base due to its syntactically terrible standard library and history as a functional language.
As such, this addition makes plenty of sense.
I can assure you that PHP is not a functional language (despite all my efforts to make it one).
2) php is procedural, not functional. (edit: whoops, beaten to this punch)
Web pages are just not suited to OO. Encapsulation can be done via functions - adding OO to it gets you nothing except longer code.
Making things more complicated does not make them better.
Maybe some other framework does this better, though.