Live data from Hacker News

These are things in PHP which make me sad

phpsadness.com

151–160 of 217 posts

Re: These are things in PHP which make me sad

#151
post #82

Earlier quoted context omitted.

What would the ideal language return for your function call foo('bar'). It would seem to me that missing an argument should return some sort of notice, like in the case where someone else is using it.

I prefer Javascript for example: JQuery's calling conventions would not be possible if function args were mandatory.

You can always use func_get_args() if you truly want it that way.

Re: These are things in PHP which make me sad

#152
post #150
post #38

Earlier quoted context omitted.

It makes sense for the same reason it makes sense in Perl: use a string as a number and you get the number that is at the start of the string. E.g., "12" == 12, and "12php" == 12.

Perl recognises that it is a bad practice. perl -we ' print "true\n" if "12" == "12php"' Argument "12php" isn't numeric in numeric eq (==) at -e line 1. true perl -w -e 'my $foo = "12php"; $foo = $foo + 1; print $foo, "\n";' Argument "12php" isn't numeric in addition (+) at -e line 1. 13 (an exception seems to be made for $foo++ though... that's Perl for you).

$foo++ isn't an exception. It has documented behavior on strings. That is sometimes very useful.

Re: These are things in PHP which make me sad

#153
post #124

I've definitely run into #1 on the list. "Paamayim Nekudotayim" is a transliterated version of פעמיים נקודתיים‎, which means "double colon" in Hebrew. Zeev and Andi are Israeli, which kind of explains it, but the error message is still pretty useless.

Of all these complaints, I’m most forgiving of the name of T_PAAMAYIM_NEKUDOTAYIM. You only need to look it up once; the cost is a few seconds of Googling and the payoff is you learn a fun random fact. It gives the language a bit of color. Still, glad I’m not doing much PHP anymore.

Actually, I kind of like the feeling that I'm building a golem when working on webapps.

Re: These are things in PHP which make me sad

#154

Earlier quoted context omitted.

It's not a bug though, it's how references work. The code is exactly right. You might not expect the output but that doesn't mean it's logically incorrect.

Yeah, I understand the cause. Just because those steps make logical sense doesn't mean it's not a bug. My real point was about the WONTFIX tendencies of the PHP dev team at the time (I've been gone a while; maybe it's better now). It's absolutely the thing I miss least about that community. I mean, when I filed that bug PHP 5 -- the first version to support foreach with references -- was less than 2 months old. The "…

It's not a bug because it's not a bug. How would you propose they fix this non-bug anyway?

At the end of the first loop, $item contains a reference to the last item in the array. Just as $item would contain the value of the last item in the array if you weren't using references. In the next loop, $item still contains that reference so now you're overwriting the value of that reference. You can't assume the second loop knows anything about the first loop.

People might actually be relying on this behavior but not in the way that you're expressing here. References are not just assigned in foreach loops.

Re: These are things in PHP which make me sad

#155
post #105

Earlier quoted context omitted.

I need more than a simple fan boy boast. Download it first and then tell me why.

I've done my time in Cold Fusion hell, I know what I need to know. Perhaps I've got a negative attitude about the intelligence of developers because I've been a maintenance programmer for too long. I've seen so many apps that almost work in ColdFusion because some guy didn't know if he was using a session scope or an application scope or request variable in CF. I worked at a place where there was a ColdFusionMafia th…

Sounds like a bad job. I've had bad jobs but I've never blamed the language.

CF is easy to get started in, so is PHP. I've seen some horrible spaghetti code in both languages. That doesn't make either of them bad.

I like CF because I like writing fewer lines of code to get things done. That doesn't stop me from looking at other languages seeing if something is better.

In fact some members of the community are blogging the seven languages in seven days book, not all of us have blinders on;http://www.bennadel.com/blog/2106-Seven-Languages-In-Seven-W...

Re: These are things in PHP which make me sad

#156
post #81

Earlier quoted context omitted.

I often find that PHP coders lack a total understanding of the LAMP stack. "Apache configuration? Huh? I don't know, our admins do that." "MySQL? I don't know, I'm not a DBA. I'm a developer." "UNIX commands?!! I don't like going in the terminal. I'm a developer." No, sorry, you're not a developer. You're a glorified web page editor.

Bullshit. You don't have to be a sysadmin to be a developer. Web devs often know the whole stack, but you're still a web dev if someone else in your company handles those parts..

Exactly. I'm trying to get into the state where the only machine where I have root is my phone or laptop.

Re: These are things in PHP which make me sad

#157
post #22

I've definitely run into #1 on the list. "Paamayim Nekudotayim" is a transliterated version of פעמיים נקודתיים‎, which means "double colon" in Hebrew. Zeev and Andi are Israeli, which kind of explains it, but the error message is still pretty useless.

Its only a "bug" because there's an unspoken rule that all programming languages should be written in English, and English doesn't have a proper word for this symbol. Pretend that English had no representation of an ellipsis, but Hebrew did. Should the language author say "Expected: dot-dot-dot" in the error message to appease native English speakers, or should (s)he use the unambiguous form?

OK, let's pretend that. Then, we have someone designing a programming language with English keywords that uses a token for which English does not have a name (not merely a well-known name, not even an obscure one, but no name at all)

IMO, that would only be a good idea when taking part in a obfuscated programming language context.

Re: These are things in PHP which make me sad

#158
post #28

What makes ME sad is no keyword arguments. Helper/wrapper functions either get an annoying and difficult-to-grok-at-glance associative-array for it's params (bad), or a huge list of rarely-used parameters (worse), or a huge set of wrapper functions to set their own paramters (even worse), or outright duplicated functions for similar-but-not-quite tasks (worst). This happens to me while producing something like a jqGr…

Hey, in case you are interested I constructed a reply to your post here: http://commonphp.blogspot.com/2011/05/keyword-functions-in-p...

In a nut shell though it's essentially a write up of my library which allows for creating keyword function wrappers so you can do stuff like:

   myStrPos(
       needle, 'peter', 
       haystack, 'is peter in here?'
   );

Re: These are things in PHP which make me sad

#159
post #16

There's a lot of valid points there, but "#33 Cannot override private methods with a subclass" is the right behavior. That's exactly what private is for, and it's important to know that such names are non-colliding and you can rely on their implementation. Use protected for overridable methods. You shouldn't mock or directly test private methods in unit tests — they're not part of the interface!

"#41 Cannot create a final abstract class" is borderline too

I like to think that declaring a class as "final" is simply a lack of imagination.

Re: These are things in PHP which make me sad

#160
post #140

Earlier quoted context omitted.

public/protected/private is a dumb idea in dynamic languages. If you don't want someone calling your method, prefix it with an underscore and say "the results are undefined if you call methods that start with an underscore". Done. Easier to maintain, easier to test, less code to type in. Come to think of it... public/protected/private is a dumb idea in C++ and Java, too.

Recently at my company we're writing a lot of JS and its' lack of "public/protected/private" doesn't make it easier to maintain or test. Actually, it's quite frustrating because you know you can't test it properly - everything public? it's a ticking timebomb, someone at some point will simply override your method somewhere and hell will broke loose

Even though JS doesn't have language constructs for public/private, there are a number of different ways to write modules with hidden members by use of closures.

Crockford explains with some examples here:

http://javascript.crockford.com/private.html

Post reply on HN