Point_log_query



  • HELLo!

    This was the original WTF I was going to post, before stumbling across the whole EA/BW mess...

    Doing some small maintenance work on a semi-popular (commercial) site in my country, as the previous developer got kicked out for not doing anything. Granted, I know of the developer in question, and have heard enough about his exploits in developing this site, to know that it's absolutely riddled with WTFs. This dev certainly had no business writing a site like this, and everything about it have been a learning experience for that person. Quite literally, everything.
    Word of warning, for those nay-sayers and "TRWTFers" out there; This is PHP code.

    However, the following piece of code just struck me as.. Well, I'll let you decide for yourself:

    <?php
    class logg {
    public function logg_point($user,$message,$time)
    {
    define("point_log_query",mysql_query("insert into `point_log` values ('$user','$message','$time')"));
    $this->error = "Error occurred with logging, contact administrator!";
    if (!point_log_query) {
    return "<p style=\"color: red;\">".$this->error."</p>";
    }
    else {
    point_log_query;	
    }
    }	
    }
    ?>

    And here's a properly indented version of it:

    <?php
    class logg {
    	public function logg_point ($user, $message, $time) {
    		define("point_log_query",mysql_query("insert into `point_log` values ('$user','$message','$time')"));
    		$this->error = "Error occurred with logging, contact administrator!";
    		if (!point_log_query) {
    			return "<p style=\"color: red;\">".$this->error."</p>"
    		} else {
    			point_log_query;
    		}
    	}
    }
    ?>

    I just felt it brought my point across in a nice and succinct manner, though what the point of the else is: Your guess is as good as mine.

    Happy codin'!



  • ... oh, wow.

    Clearly, the author didn't understand how variables work in PHP. Or classes. Or logging. Or databases. Or return values. Or had any clue of what he was doing at all.


  • 🚽 Regular

    I would have thought you'd get a fatal error for declaring a constant twice like that. Unless that function is only called once per page load?



  • @RHuckster said:

    I would have thought you'd get a fatal error for declaring a constant twice like that.

    You get a notice.


  • 🚽 Regular

    @derula said:

    You get a notice.
     

    I forget how really "forgiving" PHP is, to the point where using a constant by its definition is optional. Everywhere I've been, though, we've used a strict-mode policy where all notices are never to be ignored.



  • @RHuckster said:

    @derula said:

    You get a notice.
     

    I forget how really "forgiving" PHP is, to the point where using a constant by its definition is optional. Everywhere I've been, though, we've used a strict-mode policy where all notices are never to be ignored.

    Good thing there's error_reporting(E_NONE); you can just place in your PHP code where ever you're going to issue a notice!



  • @derula said:

    @RHuckster said:

    @derula said:

    You get a notice.
     

    I forget how really "forgiving" PHP is, to the point where using a constant by its definition is optional. Everywhere I've been, though, we've used a strict-mode policy where all notices are never to be ignored.

    Good thing there's error_reporting(E_NONE); you can just place in your PHP code where ever you're going to issue a notice!

    Isn't there a setting in the php.ini that denies the ability to set the error_reporting level from code?


  • Discourse touched me in a no-no place

    @Kazan said:

    Isn't there a setting in the php.ini that denies the ability to set the error_reporting level from code?
    http://php.net/manual/en/ini.core.php#ini.disable-functions


Log in to reply