Mistři v programování na #hovnokod

public function getContent($url = null)
    {
        $url = $url ? $url : $this->main_url;

        try {
            $client = new Zend_Http_Client($this->main_url);

            $client->setConfig(['timeout' => static::REQUEST_TIMEOUT]);
            $client->setCookieJar(true);
            $client->request(Zend_Http_Client::GET);
            $client->setUri($url);
            $client->request(Zend_Http_Client::GET);
            $tmp = $client->getLastResponse();

            $output = $tmp->getBody();

            return $output;
        } catch (Exception  $e) // flush and try again
        {
            flush();

            $client = new Zend_Http_Client($this->main_url);

            $client->setConfig(['timeout' => static::REQUEST_TIMEOUT]);
            $client->setCookieJar(true);
            $client->request(Zend_Http_Client::GET);
            $client->setUri($url);
            $client->request(Zend_Http_Client::GET);
            $tmp = $client->getLastResponse();

            $output = $tmp->getBody();

            return $output;
        }
    }

Fbtest Fbtester,

Náhodná 202 :)

function upload_images()
{
	global $user, $MSG, $system;

	if (!$user->logged_in)
	{
		// imitate code execution
		die(json_encode(array(
			'OK' => 0,
			'error' => array(
				'code' => '202', //random
				'message' => $MSG['login_required_text']
			)
		)));
	}
}

Ajťák Ajťák,


Marek Dočekal,

Skús vyhodiť výnimku

if ($this->connection->error) {
    try {    
        throw new \Exception("MySQL error " . $this->connection->error . " <br /> Query:<br /> {$queryStr}", $this->connection->errno);    
    } catch(\Exception $e ) {
        echo "Error No: ".$e->getCode(). " - ". $e->getMessage() . "<br >";
    }
}

Anonymous,

Outsourcing istej nemenovanej BA firmy, ktorá sa nehanbí za takéto skvosty vypýtať si veľké peniaze. Kiež by však toto bolo to najhoršie z celej ich práce na veľkom projekte, ktorý som teraz zdedil...

<?php
class Foo {
    private function getAbc()
    {
        return "result";
    }
    
    public function get($name)
    {
        $fun = 'get' . ucfirst($name);
        return $this->$fun();
    }
    
    public function getAbcById($id)
    {
        $list = $this->get("abc");
        //.....
    }

}
?>

Anonymous,