Skip to content
DevMeme
5355 of 7590
Languages Post #5872 · source on Telegram

When enableExceptions(false) actually silences them - PHP strikes again

Description

The image is a dark-mode screenshot of a social-media post by a user named “Arian van Putten (@ProgrammerDude).” The post reads in full: “$db->enableExceptions() disables exceptions in PHP as it takes an optional parameter $enable that defaults to false. This language is seriously ill.” Beneath the text are standard tweet metadata - timestamp “15:33 · 27/12/2023 from Earth,” view count “23 K Views,” and engagement counts showing 23 reposts, 4 quotes, 271 likes, and 14 bookmarks. The humor hinges on a mis-named PDO method whose default argument creates a double negative: calling enableExceptions() with no arguments actually *disables* exception throwing in PHP because the $enable flag defaults to false. Senior developers will recognize the API-design antipattern, the hazards of boolean default parameters, and the perennial complaint that PHP’s naming conventions feel like an archaeological dig through 25 years of backwards compatibility

Comments

116
Anonymous ★ Top Pick Somewhere in the PHP core someone wrote `enableExceptions(false)` and thought, “Perfect - self-documenting code.”
  1. Anonymous ★ Top Pick

    Somewhere in the PHP core someone wrote `enableExceptions(false)` and thought, “Perfect - self-documenting code.”

  2. Anonymous

    After 20 years in the industry, I've learned that PHP's enableExceptions(false) is just the language's way of preparing us for production - where exceptions are enabled but error reporting is disabled, logs are write-only, and the only debugging tool is customer complaints

  3. Anonymous

    Ah yes, PHP's `enableExceptions($enable = false)` - because nothing says 'enable' quite like defaulting to 'disable'. It's the API design equivalent of a fire alarm that's off by default. At least it's consistently inconsistent with PHP's long tradition of making you question whether you're the one who's confused or if the language designers were just having a laugh. This is the kind of footgun that makes you appreciate languages where 'enable' actually means 'turn on' and not 'maybe turn on if you remember to pass true, otherwise definitely keep off'. It's like ordering a coffee and having to explicitly specify you want it hot, or it arrives frozen

  4. Anonymous

    PHP's enableExceptions(false): the API equivalent of a 'Do Not Enter' sign on the exception highway - silent crashes for all

  5. Anonymous

    Nothing says enterprise maturity like enableExceptions(false): a boolean trap preserving backward compatibility while maximally violating the Principle of Least Surprise

  6. Anonymous

    Only in PHP do you call enableExceptions() and, by default, get fewer exceptions - Boolean Trap meets naming inversion, the kind of DX that turns observability into an optional parameter

  7. @claudio_tg 2y

    Still better than Java

    1. @dsmagikswsa 2y

      I doubt it... at least the namespace system in Java is much better than PHP....

      1. @RiedleroD 2y

        depends. better at making simple websites? definitely better at doing literally anything else? probably not

        1. @dsmagikswsa 2y

          people use JS for website nowadays...

          1. @RiedleroD 2y

            and people use pizza cutters to cut pizza, that doesn't mean they're actually good at that

            1. @RiedleroD 2y

              (yes, pizza cutters are absolutely worse at cutting pizzas that knives are if you don't sharpen them. and nobody does)

              1. @dsmagikswsa 2y

                I think JS is the knife and people keep cutting themselves and the people around...

                1. @RiedleroD 2y

                  js is the pizza cutter, but they cut past the pizza and into the table php is a saber. I'm sure you can cut pizza better with that, but my god does it look silly

  8. @Agent1378 2y

    The PHP is fine. The script kiddy that used a function without consulting the manual (took code from so? ) - is a лох on the other hand

    1. @sylfn 2y

      Counterintuitive functions, fucked up nuances, a lot of ways to get rid of one's leg...

      1. @sylfn 2y

        If you are masochistic, you can say PHP is fine --- just like that dog in the room full of fire

      2. @Agent1378 2y

        C/c++ described!

        1. @sylfn 2y

          C++ is fucked up too, lmao

          1. @Agent1378 2y

            Ok, out of interest, what is not?

            1. @sylfn 2y

              Any language is fucked up, ot certain extent

        2. @Zoom7654 2y

          at least there are pros :)

    2. @purplesyringa 2y

      No, PHP is not fine. They could have avoided this problem by making the argument required. Other modifications are possible too, like using setExceptionsEnabled as opposed to enableExceptions, but the simplest one would suffice. And they didn't do even that...

      1. @RiedleroD 2y

        or make it default to true instead of false or call it disableExceptions php is troubled but it's still not as bad as js :3 *scuffle ensues*

      2. @AlexanderRomanov46 2y

        Read my comment above, girl

    3. @AlexanderRomanov46 2y

      Never seen anything counterintuitive in php, 10 years in dev.

      1. @purplesyringa 2y

        you've got functions named strrev and str_pad, you've got many equivalent names like join and implode, you've got many tools for almost the same task like print_r and vardump, which provide their result via different methods (stdout and return value), and they all accept slightly different arguments (like str_contains($haystack, $needle) and in_array($needle, $haystack)), they sometimes return NULL and sometimes false and sometimes 0. Functions that may error typically return false on error, meaning that boolean functions have to return 1 or 0 on successful true/false result instead...

        1. @AlexanderRomanov46 2y

          Somehow it did not stop me to get the job done and deploy in production stuff that currently work in generate money and jobs.

          1. @purplesyringa 2y

            Right. It still isn't intuitive, though.

        2. @anatoli26 2y

          true story

      2. @anatoli26 2y

        are u still generating html by hand in php?

    4. @kitbot256 2y

      Who блять expects ->enable() method to disable everything?

      1. @sylfn 2y

        a php developer

  9. @Valithor 2y

    I think the thing folks are also missing about this 'language' problem is that the code is referencing the functions of an object without even calling out the name of the class being used?? It's part of the SQLite3 extension and I don't even know anyone who uses it; The only ones I've seen people regularly use are either PDO or mysqli

    1. @Agent1378 2y

      People are using native (no pdo) pgsql and oci classes, so maybe this too

  10. @Valithor 2y

    https://github.com/php/doc-en/blob/master/reference/sqlite3/sqlite3/enableExceptions.xml this method's class was made 8 years ago and nobody ever even made a pull request to change the name. People must not care enough.

    1. @RiedleroD 2y

      > to change the name my person in christ, you can't just change a function's name

      1. @purplesyringa 2y

        You can though

        1. @RiedleroD 2y

          you can't just break back-compat, no

          1. @purplesyringa 2y

            You can in a major version

            1. @RiedleroD 2y

              if php breaks back-compat in a major version imma be majorly pissed, tell you what php is supposed to be a super stable language I expect my php7 stuff to work on php8 just the same

              1. @purplesyringa 2y

                Come on, they break backcompat all the time. Like, check out https://www.php.net/manual/en/migration83.php and other pages in the sidebar

              2. @kitbot256 2y

                Every php5.2>5.3>5.4 update was breaking something. Why 7>8 should differ?

                1. @RiedleroD 2y

                  because I say so

    2. @CodeProger 2y

      https://php.watch/versions/8.3/SQLite3-exception-improvements

  11. @anatoli26 2y

    seriously ill is the person who still uses php

  12. @dsmagikswsa 2y

    People judge a language by the weird implementation of a library is weird...

    1. @purplesyringa 2y

      It's about the same in stdlib too though

      1. @dsmagikswsa 2y

        I don't know much php, but I think of people use PDO nowadays, right?

        1. @purplesyringa 2y

          I didn't mean just databases, sorry, I meant the whole stdlib

    2. @RiedleroD 2y

      PDO is stdlib I think

      1. @RiedleroD 2y

        (and that looks like it's PDO)

  13. @RiedleroD 2y

    you scare me. I will absolutely not fight you. you're chaotic and unpredictable

  14. @SheepGod 2y

    and all i use is php and js 🥲

  15. @kromberged 2y

    Oh man, you don’t know fcking perl

    1. dev_meme 2y

      Going that deep is a highway to a psychiatric hospital

      1. @purplesyringa 2y

        Perl's *cute*, but it sorta feels like I'm talking to a really dumb AI, but an AI nonetheless. It sorta tries to emulate what people would say in English, simplifying common tasks with stuff like unless and while (<>), but that's also what makes *reading* code difficult, and writing too, because you might want to use a construct Perl doesn't understand. But the same applies to GPT-based programming too, and I really don't understand why the latter is so popular while Perl is typically hated on.

        1. @sylfn 2y

          why not hate both

          1. @purplesyringa 2y

            Well I do, but I'm in the minority

        2. dev_meme 2y

          By GPT-based programming you mean the totally useless positions that even kids can go for prompt engineers?

          1. @RiedleroD 2y

            the hard part of being a prompt engineer is convincing your boss you're actually needed (because you're not)

            1. dev_meme 2y

              Guess it's not so hard, you have successfully convinced chatgpt to do what you need after all🙂

              1. @RiedleroD 2y

                "chatgpt, write me a reason why I should keep this job"

        3. @mira_the_cat 2y

          btw there were perl library to write perl code in latin

          1. @mira_the_cat 2y

            https://metacpan.org/dist/Lingua-Romana-Perligata/view/lib/Lingua/Romana/Perligata.pm

  16. dev_meme 2y

    Every language is fucked up in its own way, though some of them are leaning towards unfucking themselves while others go the opposite way, that's how you can choose a better one if you're not masochist

  17. @RiedleroD 2y

    🤭

  18. @AlexanderRomanov46 2y

    Its not about the language, its about that concrete Sqlite library implementation, that is extention to php, writen by someone. That gullible soy cant distinguish language and it's implementation.

  19. @AlexanderRomanov46 2y

    It's the same if you dive in shit written project and blame the language on it. Blame specific people, who did concrete shit. Even weak languages and platforms (php not one of them) can be used to write decent projects if you know wacha doing.

  20. @AlexanderRomanov46 2y

    They main problem with php is that, it was just a web template language and because there was no alternative, community turned it into general server language. Thats what some of the languages flaws come from. But the benefit of the rapid development outweighs all of them.

    1. @anatoli26 2y

      that's true that at that distant point in the past php was mostly the only lang for the web, but 20 years passed already since then.. for those who're still using php I suggest you get familiar with rust. For webdev (and almost everything else) it's god-sent. Was writing backends in php for 10 years, 10 years ago.. only in nightmares I see php again

      1. @purplesyringa 2y

        Is Rust just as good for templates though?

        1. @anatoli26 2y

          what type of templates?

          1. @purplesyringa 2y

            You know, stuff like <title><?= get_title() ?></title> :)

            1. @purplesyringa 2y

              I meant any template language like jinja

            2. @anatoli26 2y

              😆 u don't do that anymore.. raw html is a no-go

              1. @purplesyringa 2y

                Yeah, yeah... What else do you use, SSR?

                1. @anatoli26 2y

                  check this: https://dioxuslabs.com. Dioxus is a rust framework that allows you to write server and client components from within the same file, you just annotate that some func should run on the front and another on the back and this framework will create all the stuff needed to make a REST request from a browser to the server. And you can target all 6 platforms: 3 desktops (win, linux, mac), 2 mobile (iOS and android) and the web (browser), with practically no code change

                  1. @AlexanderRomanov46 2y

                    jizz, some another "new and fancy" framework that will die faster, than Ruby did. Probably it's not in the competence of it's developers to inject a variable into website, instead of "2023" literal.

                    1. @anatoli26 2y

                      sure, that's a huge conceptual error, i'll just through it away and get back to php

                      1. @AlexanderRomanov46 2y

                        Today every open-source product is still a product, like an Iphone. I just don't buy all that stuff that is written on their page, like "Install me, I am another silver bullet" Thx, I'll just stick with Flutter and PHP.

                    2. @anatoli26 2y

                      also you know that you actually put copyright year(s) for the year(s) when the stuff was written, not the current year automatically.. if nothing was written during 2024, no need to update anything. That shouldn't be done automatically

                      1. @AlexanderRomanov46 2y

                        If the content of their website will be updated, they should update the copyright date. Probably that didnt update their website for some months from now or just lazy.

                2. @anatoli26 2y

                  Dioxus actually has 3 ways to render HTML (SSR with hydration on the client is one of them): https://dioxuslabs.com/learn/0.4/getting_started/choosing_a_web_renderer

                  1. @anatoli26 2y

                    and of course this is just one way of doing things.. you can do it in 2 other ways, see the docs 👆 about HTML renderers

                3. @anatoli26 2y

                  + tailwind CSS framework (https://tailwindcss.com/docs/installation) for everything CSS (responsive designs, etc.)

            3. @anatoli26 2y

              So you write something like 👆this like that: pub fn App(cx: Scope) -> Element { render! { StoryListing { story: StoryItem { id: 0, title: "hello hackernews".to_string(), url: None, text: None, by: "Author".to_string(), score: 0, descendants: 0, time: chrono::Utc::now(), kids: vec![], r#type: "".to_string(), } } } }

      2. @anatoli26 2y

        though Rust vs C or PHP is a complete paradigm shift, so it'll take time to understand and get used to the new concepts and ways of solving things

      3. @AlexanderRomanov46 2y

        Well, I prefer "horizontal" self-development, not a "vertical", when you learn something over and over. I know one backend platform, no need to learn another. Better learn frontend, team management etc, to be able to know all the full cycle.

      4. @AlexanderRomanov46 2y

        Doubt that.

  21. @AlexanderRomanov46 2y

    I am sure I will find some "counterintuitive" stuff in any of the languages anyone likes. All the hate onto anything abstract, that cant answer back, like programming language or other nation, comes from people that just hate their lives.

  22. @qtsmolcat 2y

    Understandable

  23. @anatoli26 2y

    Check the docs: https://dioxuslabs.com/learn/0.4/guide/your_first_component

  24. @anatoli26 2y

    so you target all the 6 platforms from the same codebase with no effort

    1. @purplesyringa 2y

      oof, i just hope platform support is not *equally bad*

      1. @anatoli26 2y

        What do you mean?

        1. @purplesyringa 2y

          if you target multiple platforms with one codebase, it's likely that you won't have native interfaces on many of them; and if you do, they won't look equally good everywhere

          1. @anatoli26 2y

            the interface isn't done with native components, it's a webUI, exactly the same on all platforms, e.g. like Telegram

  25. @anatoli26 2y

    sometimes people just want to suffer for free.. 🤷‍♂️

    1. @AlexanderRomanov46 2y

      I am sure HR's will be suffering in X years from now, when they try to find some adequate developers to maintain a project written on a dead platform.

  26. @AlexanderRomanov46 2y

    If you do this for yourself only, it's okay, if you make money on it. Commercial and enterprise development? No way.

    1. @anatoli26 2y

      the dev effort and time-to-market speed of this stack is just so much better that php just can't compare.. and this is not to mention the security and performance

      1. @AlexanderRomanov46 2y

        Show me typical Request-Controller-Handler-Response example with this

        1. @anatoli26 2y

          Here https://dioxuslabs.com/docs/nightly/guide/en/fullstack/server_functions.html you have an explanation with an example of a client-server app with both components written in the same file

          1. @AlexanderRomanov46 2y

            So you do "routing", "request formalization / validation" and "response" in one file It's not SOLID

            1. @anatoli26 2y

              of course you can split everything the way you want, it's just a demonstration that the frameworks abstracts the separation between server and client and you work with it just as if it was a single monolithic app

              1. @AlexanderRomanov46 2y

                Sounds like nonsense "separation between server and client" "single monolithic app"

                1. @anatoli26 2y

                  Also, in Rust in general you don’t need to validate client requests the way you do it in PHP. Rust is strongly typed language, so you just need to define the structures and the possible states, and then you just deserialize the request (or it fails and you reply with an error)

  27. @anatoli26 2y

    fn app(cx: Scope<usize>) -> Element { .. } runs on the client, async fn double_server(number: usize) -> Result<usize, ServerFnError> { .. } runs on the server

  28. @anatoli26 2y

    The communication between the client and the server is done 100% by the framework, for the developer it's like the same executable and you just call a local function

  29. @anatoli26 2y

    ok, stay with php, I see the Rust paradigm shift is not for you

  30. @anatoli26 2y

    Though with Dioxus you don’t need even that, nor the routing as you know it, it abstracts you from the client-server separation and allows you to write it as if it were a single app (i.e. without a server)

  31. @anatoli26 2y

    I already said that learning Rust implies a paradigm shift and this is what makes it somehow complex to learn. You can’t write something more complex than helloworld without extensive reading of the docs and understanding of its paradigm, that’s why it has a steep learning curve.. I’d say it’s more complex to grasp than C - you should understand process memory layout better that when writing in C, though most of the time you don’t touch memory directly

  32. @anatoli26 2y

    But once you understand it, it’s pure pleasure to use it from all points of view: ease of use, speed of development, developer’s efficiency, correctness of code, performance, security..

  33. @anatoli26 2y

    And with WebAssembly and WebGL (and already WebGPU) you can run things like Quake and AutoCAD in a web browser or webview elements on desktops and mobile, i.e. there's absolutely no limit to what you can achieve in visual aspect and UX, your creativity is the only limit

  34. @nepalymiynik 2y

    I'll never back to that shit again

Use J and K for navigation