• Tim (unregistered)

    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.

  • (nodebb)

    Or at least was widely used when Anton submitted this, which was some time ago- we could hope the code has been improved since then

    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.

  • DQ (unregistered) in reply to Steve_The_Cynic

    I think your odds on the lottery are much higher...

  • (nodebb) in reply to DQ

    @DQ So do I.

  • Sauron (unregistered)

    <?php echo "PHP is"; ?> TRWTF

  • (nodebb)
    You want to split a string? We call that explode because that's way more radical than split.

    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.

  • Jason Stringify (unregistered)

    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.

  • K (unregistered)

    I don't know much PHP, but how is that code supposed to be written using implode?

  • (nodebb)

    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); ?>

  • TheCPUWizard (unregistered)

    Reminds me of when I wrote "plode" (to change the separator in a concatenated string, of course)

  • ttlanhil (unregistered) in reply to Dragnslcr

    Of course you can argue about the WTFness of inheriting everything from Perl, but that's a separate argument.

    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)

  • (nodebb) in reply to Tim

    I always assumed each PHP block was executed separately.

    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.

  • Michael R (unregistered) in reply to Sauron

    IFTFY

    <?php echo "PHP is"; ?>&nbsp;TRWTF
    
  • Argle (unregistered)

    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.

  • (nodebb) in reply to Jason Stringify

    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

    There isn't A language like that. There's at least two that I can name: Perl and PHP.

  • (nodebb) in reply to Steve_The_Cynic

    ... and PowerShell

  • Brian Boorman (unregistered) in reply to Jason Stringify

    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.

  • matt (unregistered)

    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.

  • (nodebb) in reply to Jaime

    OK. I don't use Powershell enough to remember that sort of thing about it. (My job is on Linux and FreeBSD, not Windows...)

  • (nodebb) in reply to Dragnslcr

    it was inherited from Perl.

    Actually, PHP started out as a Perl program.

  • (nodebb) in reply to Steve_The_Cynic

    And Dart uses $ within a quoted string to indicate interpolation (very Perl-like).

  • dusoft (unregistered) in reply to miquelfire

    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

  • (nodebb) in reply to Steve_The_Cynic

    "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.)

  • (nodebb) in reply to Jaime

    Modern view languages like Razor work the same way, too.

  • (nodebb) in reply to Jaime

    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:

    PowerShell uses the $ prefix for variables to distinguish them from other types of commands and objects in the shell. This convention helps to easily identify and parse variables within scripts, especially in a command-line interface where variables are often mixed with functions, commands, and other syntax.

    The $ prefix comes from PowerShell’s roots in Unix-like shells such as Bash, where the same symbol is used to reference variables. This aids in improving readability and consistency across various command environments. Additionally, using $ for variables helps avoid conflicts with command names, making it clear when a variable is being referenced.

    By utilizing $, PowerShell provides a cleaner way to parse variables, especially in scripts where objects and commands can be heavily intertwined.

    Addendum 2024-09-05 17:43: My question for ChatGPT was: "Why does PowerShell have dollar prefix for variables?"

  • mihi (unregistered)

    TIL that PHP has endif.

    https://www.php.net/manual/en/control-structures.alternative-syntax.php

  • löchlein deluxe (unregistered) in reply to Dragnslcr

    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.

  • Darren (unregistered) in reply to Jason Stringify

    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.

  • Ross Thompson (unregistered)

    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.

  • (nodebb)

    I've been using those alternative control structure syntaxes for around 20yrs now :)

  • (nodebb) in reply to Ross Thompson

    $flag starts out as false, so in the first iteration, the if condition fails and thus the glue string ', ' is not printed.

    $flag is then set to true and finally the item is printed. On each iteration thereafter, $flsg is true and the glue string is printed before each remaining item.

Leave a comment on “Strings go Asplodey”

Log In or post as a guest

Replying to comment #:

« Return to Article