• (nodebb)

    PHP has an alternate syntax for blocks

    No, it doesn't. It has an alternative syntax for blocks. See e.g. https://www.php.net/manual/en/control-structures.alternative-syntax.php

    It's quite clearly an alternative syntax, both in the URL and the actual page of docs.

    Hmm. Apparently, the use of "alternate" to mean "alternative" is a strong Americanism. I suppose I could be persuaded to forgive you... ;)

  • And yet it runs (unregistered)

    Looks like the colon syntax is meant for when you mix your PHP with HTML, just to make it easier to read.

    <?php if ($condition): ?>
        <p>Content shown if true</p>
    <?php elseif ($other_condition): ?>
        <p>Content shown if other is true</p>
    <?php else: ?>
        <p>Content shown otherwise</p>
    <?php endif; ?>
    

    Also note that you have to use elseif instead of else if when using colon syntax.

  • Smithers (unregistered)

    meaning we get four months of January, which just seems cruel, honestly, at least in the Northern Hemisphere.

    We're getting them in place of October-December, so it's not like we're missing summer or anything. Honestly just skipping the slow descent through autumn and getting straight into the thick of winter might not be a bad thing. Only downside I see is Christmas... no, not skipping it: Russian Christmas is in January, so this way you have to go through that rigmarole four times in a row! (NB I have not checked whether those months are actually Russian or another language with the Cyrillic alphabet.)

  • Rhailto101 (unregistered)

    Method get_the_date() is not a Core PHP Method. It is from "WordPress Developers Resources" (url: ...//developer.wordpress.org/reference/functions/get_the_date/).

    Admittedly WordPress is a PHP Application but, despite the pervasive meme that "PHP is bad", it is not PHP's fault. For your convenience (and it should have been referenced in the Article to give the Judgement some credence), The Method is:

    function get_the_date( $format = '', $post = null ) { $post = get_post( $post );

    if ( ! $post ) {
    	return false;
    }
    
    $_format = ! empty( $format ) ? $format : get_option( 'date_format' );
    
    $the_date = get_post_time( $_format, false, $post, true );
    
    /**
     * Filters the date of the post.
     *
     * @since 3.0.0
     *
     * @param string|int $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
     * @param string     $format   PHP date format.
     * @param WP_Post    $post     The post object.
     */
    return apply_filters( 'get_the_date', $the_date, $format, $post );
    

    }

    The "warthog" in me could not find the will to explore further. I.e. track down the other "methods" invoked.

  • f222 (unregistered) in reply to Smithers

    They effectively do look like Russian but in feminine form. Don't know if it's another WTF or a country dependent thing though 🤔

  • (nodebb) in reply to Smithers

    We're getting them in place of October-December, so it's not like we're missing summer or anything. Honestly just skipping the slow descent through autumn and getting straight into the thick of winter might not be a bad thing.

    Heretic. Blasphemer. Autumn is infinitely superior to all other seasons. None of the other seasons have Halloween, for example. Or Thanksgiving. Okay, I'm clearly American, so you've tuned out already. Bye.

  • (nodebb) in reply to f222

    They are in the genitive case, which is proper when used within a date. However in that case, they should not be capitalized, which the array values seemed to be. So still one more oddity.

    Anyway, the entire thing looks like new code that the next intern will get to debug next Winter.

    Also, if you google 'php convert date', it only takes a few seconds to find at least one example which suggest a regex is the best way to do this, instead of, you know, using internal functions already present to scan dates. Because clearly library date functions have to be slower then making your own. One can never trust libraries.

  • COBOL Dilettante (unregistered)

    Maybe the writer is among the oldest of Old Calendarists, and rejects the 12-month innovation of the Julian reforms

  • A Human (unregistered) in reply to Ross_Presser

    Autumn is the best. It's not too hot, it's not too cold (although it gets a little messy because all the leaves come off the trees. In my corner of the world halloween happens in spring. Spring kind of sucks. The weather is really stormy, the stores have put out all the obnoxious Christmas adverts even though it's like 4 months away, and if you don't put up a no halloween sign, when it comes to october you get an endless stream of door knockers ignoring your no soliciting sign.

  • PedanticRobot (unregistered)

    The alternative syntax is what really gives PHP its power as a templating language, removing the need for a bunch of string munging when all you want to do is pop some variables into some markup. I made a good living in my younger days building bespoke blog engines using that syntax and will happily still sing its praises.

  • (nodebb)

    I've used the alternative syntax for blocks for decades :)

    It allows you to not have to 'echo' out the HTML code, you just put the fancy blocks in and then put regular HTML in-between.

  • Álvaro González (github)

    PHP got a proper date/time library 20 years ago and it still holds up today. But, yes it's physically possible to ignore it and write back custom code, so PHP clearly sucks.

    Addendum 2026-06-03 06:27: *bad

  • (nodebb)

    Is all of this because someone thought that the number "01" is different from "1" and that the month lookup would fail? I don't do much PHP, does it just need a cast to int?

  • (nodebb)

    The ARGHHH!!! for me is those functions should be named date_get() date_explode() date_foo() etc.

  • Bruno Lustosa (unregistered)

    The while inside the if is not a WTF, and makes sense in this case. The if provides alternative content in case there are no posts to be listed. The block of code doesn't show the "else", but it should be there. It's like:

    if (have posts) { while (have_posts()) { // list the posts } } else { print "there are no posts to show" }

    Without the else, in case there are no posts, it will just display nothing instead of a meaningful message.

  • Bruno Lustosa (unregistered)

    Also, the "alternative" syntax (endif, endwhile, endfor, etc) is useful when you have several closing tags one after the other. Helps you know what is closing where.

    Instead of:

    }
    

    } }

    you'd have:

    endwhile;
    

    endfor; endif;

    But yeah, nothing a modern IDE wouldn't help you with.

  • gman003 (unregistered)

    The code style that I enforce on my PHP codebase is to use curly braces only if they are opened and closed within the same PHP code block (<? ?>). If you open a conditional/loop in one block but close it in another, use the alternative syntax. This keeps things nice and concise in files that are dedicated code blocks, but makes it much easier to find the start and end of a loop in view files, where the braces might otherwise be easily lost in all the HTML.

    I have also mandated the use, wherever possible, of typed parameters and returns, variables are to be declared before use, and the standard library is to be used whenever a function exists. Stuff like that - plus basic code quality - keeps at bay the horrors so often found in PHP codebases.

Leave a comment on “Blocked the Date”

Log In or post as a guest

Replying to comment #:

« Return to Article