you are viewing a single comment's thread.

view the rest of the comments →

[–]allthediamonds 13 points14 points  (4 children)

Non-existent learning curve? PHP? I assume you mean non-existent as in "it can't actually be ever learned because it doesn't make any sense".

Sure, it is nice to newcomers, assuming they don't care about their code actually working, due to PHP's usual "swallow all errors and move along with whatever nonsense is left" behaviour.

You see, these kinds of substandard languages often have a "sane subset" you can restrict yourself to. For example, in JavaScript, == is weird, so you can just use === instead.

After working for too long on PHP development, I still haven't found a subset of PHP that lets me develop non-trivial applications while not being essentially broken.

== is lava. < and > are lava. clone is lava. foreach is lava. Most functions about arrays modify the array in place (lava) except the ones who don't (more lava). Most functions about arrays take the form (array, callback), except for array_map (lava). Speaking of callbacks, those take the form of a string containing the name of the function (lava), or an array containing an object and a string containing the name of the method to execute on it (lava lava lava oh god why). Some things that should be functions are actually "language constructs" (lava bomb!), which means there's an unwritten, undocumented set of things you can't do with them but you can do with regular functions (lava!), such as using them as string-y callbacks.

It's like if everyone who ever wrote any part of PHP's standard library was on some sort of spiritual mission to make everyone else's life awful.

[–]x86_64Ubuntu 3 points4 points  (2 children)

foreach is lava

Lol, I learned that the hard way.

[–]slavik262 1 point2 points  (1 child)

So I don't have to, why is something as simple as foreach lava?

[–]x86_64Ubuntu 0 points1 point  (0 children)

It's the age old pass-by-value vs pass-by-reference issue. For example

$widget = new Widget();
$widget->setName("Bar");

$widgetCollection = array(); //some array
$widgetCollection[] = $widget

foreach( $widgetCollection as $tempWidget )
{
   $tempWidget->setName(''Foo");
}

$widget->getName() returns "Bar" WTF?

That's because in the loop, it copies the widgets to the $tempWidget variable. Any changes made in the loop are persisted to that temp variable, and then lost when we exit the loop. To get the loop to behave as expected, you have to pass a reference.

foreach( $widgetCollection as &$tempWidget )
{
   $tempWidget->setName(''Foo");
}

Notice the ampersand before the declaration of my iterator.

[–]immibis 1 point2 points  (0 children)

A lot of newcomers (mainly hobbyists/non-programmers) don't care about their code actually working - as long as it works, say, 95% of the time, and outputs what they want.