- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Hmm I have to say that in all my PHP experience (which, to be fair, is only about 25 minutes), it had never occurred to me that you could have php blocks that weren't valid syntax units in their own right. I always assumed each PHP block was executed separately.
Admin
Yeah, and I could hope that I'll win the big prize on the lottery every time I buy a ticket. Neither of these hopes is going to pan out, though.
Admin
I think your odds on the lottery are much higher...
Admin
@DQ So do I.
Admin
<?php echo "PHP is"; ?> TRWTF
Admin
This one isn't a WTF on its own. PHP did have a function called split; it split a string on a regular expression, and it was inherited from Perl. PHP had to create explode because having split work differently than it does in Perl would have been confusing for a lot of PHP developers that were coming from Perl.
Of course you can argue about the WTFness of inheriting everything from Perl, but that's a separate argument.
Admin
The real WTF: the fact that in 2024 there is a widely-used language where variable names have to be marked with a dollar sign.
Admin
I don't know much PHP, but how is that code supposed to be written using implode?
Admin
Assuming the whitespace between the ?> and <?php in the code is being consumed (I didn't code like that in PHP for long. Actually, when I last used the whole PHP inside HTML bit, I think PHP was only version 4.something, and 5 may not have been in beta yet) the implode code would replace the whole foreach block like so (don't know if code blocks work in the comments):
<?php echo implode(', ', $orderId=>$incrementId); ?>
Admin
Reminds me of when I wrote "plode" (to change the separator in a concatenated string, of course)
Admin
If it had, it'd at least be more intuitive for a perl coder PHP has (or at least had when last I had to look, mumble years ago) a mix of inheritance from perl, some from C (or stdlib), some from elsewhere (or in the style of one of the previous ones) Perl did inherit a bunch of its names from C as well, but it's (IMO) at least a bit more of a consistent language (whether it's consistently good is up to the reader)
Admin
It was a thing 25 years ago. Classic ASP worked the same way. It was done so you could do something very "web 0.9" like put a literal html table row inside a for loop.
Functionally, all the interpreter does turn literal blocks into echo statements and the whole page can be executed as a single block of code.
Admin
IFTFY
Admin
I'm going to get some PHP fan fuss at me for saying this, but after having both created and maintained a lot of PHP code, I have concluded that it's only possible to produce ugly code in PHP. Just some can be more ugly than others.
Admin
There isn't A language like that. There's at least two that I can name: Perl and PHP.
Admin
... and PowerShell
Admin
Is that really any different from a widely used language that requires you to put semicolons after each statement? In both cases it's just a syntactic choice.
Admin
The article's last sentence needs a period output to the end of it (as well as a fix, please god, to that unspaced hyphen-dash you think looks cool). Well, near the end of it, obviously not outside the parentheses that contain the whole sentence.
Admin
OK. I don't use Powershell enough to remember that sort of thing about it. (My job is on Linux and FreeBSD, not Windows...)
Admin
Actually, PHP started out as a Perl program.
Admin
And Dart uses $ within a quoted string to indicate interpolation (very Perl-like).
Admin
Incorrect: https://www.php.net/implode The syntax is easy, just provider a separator and an array of elements: implode(string $separator, array $array): string
Admin
"There ARE" at least two, not "there is" (there's).
Sorry, it's one of my English pet peeves. (And I admit that my English is by no means stellar.)
Admin
Modern view languages like Razor work the same way, too.
Admin
PowerShell MIGHT (big MIGHT there) have an excuse insofar it's a language designed to be a shell language, like DOS batch, Linux bash, etc. I'm not saying that's the stated excuse, nor that I'm buying this excuse, but wanted to mention it just in case.
I typed the above, then asked ChatGPT, here's what it said:
Addendum 2024-09-05 17:43: My question for ChatGPT was: "Why does PowerShell have dollar prefix for variables?"
Admin
TIL that PHP has endif.
https://www.php.net/manual/en/control-structures.alternative-syntax.php
Admin
Is that what it was? I have a vague recollection that they chose some function names to avoid hash collisions, but I can't be arsed to research that.
Admin
I don't think there's anything wrong with identifying variables with a dollar sign - in fact, I like it. It provides a very quick way of knowing what is a variable and what is a keyword.
If you're an old-hand with a language then you might know all the keywords, but if you're just learning - or it's a language you only dip into infrequently - then these little visual clues are incredibly useful.
Admin
The worst part or this that I can see, and that no-one has mentioned yet is that $flag is set to true on the first loop, so only the first two elements will be separated by a comma.
Admin
I've been using those alternative control structure syntaxes for around 20yrs now :)
Admin
$flag
starts out asfalse
, so in the first iteration, theif
condition fails and thus the glue string', '
is not printed.$flag
is then set totrue
and finally the item is printed. On each iteration thereafter,$flsg
istrue
and the glue string is printed before each remaining item.