- 1
- 2
- 3
- 4
- 5
function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
return @unserialize( $original );
return $original;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+164
function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
return @unserialize( $original );
return $original;
}
Wordpress <3
is_serialized тоже блещет
https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/functions.php#L265
+161
public function change_password() {
if (!oauth_verify_client($this->client_id, $this->client_secret, 'user/password')) {
echo json_encode(array('status' => 403, 'error' => array('code' => 5, 'description' => 'accessError')));
}
$email = $this->input->post('email');
$new_password= $this->input->post('new_password');
//...
"Тебе сюды нельзя, но так уж и быть, поменяю..."
+159
function decode_php_abbr($abbr){
if(strpos($abbr,'PHP')!==false){
$abbr=str_replace('PHP','PHP: Hypertext Preprocessor',$abbr);
decode_php_abbr($abbr);
}
else echo $abbr;
}
decode_php_abbr('PHP');
Расшифровываем аббревиатуру PHP или когда на работе немного скучно.
+166
define("DB_YESTERDAY",date('d/m/Y', time()-172800-86400-86400-86400
-86400-86400-86400-86400-86400-86400-86400-86400-86400-86400-86400
-86400-86400-86400-86400-86400-86400-86400-86400-86400-86400)); //если более 2 дней подряд были выходные, валюты не показывались. Дописано "-86400"
Дописано -86400? Забыли упомянуть, что 24 раза(
+158
/*...тут много строк...*/
if($arraySection[$section_id[$j]]=='0'){
echo '';
}
else{
echo '
<li><a href="/'.$arraySection[$section_id[$j]].'">'.$arraySection[$section_id[$j]].'</a></li>
';}
/*...тут много строк...*/
Любитель else
+161
if (($arrRoleInHold = $this->syncByToken($token)) && (!$arrRoleInHold)) {
throw new Exception('');
}
хорошее условие!
+162
class StupidClass
{
public function __toString()
{
return 'this';
}
public function hax()
{
return $this === $$$$$$this;
}
}
var_dump((new StupidClass)->hax()); // true
Уииии
+155
<?php
function load ($file) {
static $files = null;
$files or $files = [];
if (!isset($files[$file])) {
require($file);
$files[$file] = true;
}
}
$times = 1000000;
$time1 = microtime(true);
for ($i = 0; $i < $times; $i ++) {
require_once('inc.php');
}
$end1 = microtime(true) - $time1;
$time2 = microtime(true);
for ($i = 0; $i < $times; $i ++) {
load('inc.php');
}
$end2 = microtime(true) - $time2;
echo "require_once = $end1 vs \nload = $end2";
Вот это да... require_once работает в ~8 раз медленнее чем функция load. Вывод:
require_once = 16.962311029434 vs
load = 2.6861710548401
Содежания файла inc.php:
<?php echo 'Hello, world!';
+151
$friends = mysql_query("(SELECT * FROM `friends` WHERE `from` LIKE '{$act}' AND `to` LIKE '{$act}' AND `isaccepted` = '1') UNION (SELECT `id` , `name` , `surname` FROM `users_info`);");
$friend = array();$loop=0;
while($fetch = mysql_fetch_assoc($friends)) {
if ($fetch['from'] == $act) $search=$fetch['to']; else $search=$fetch['from'];
$friend[$loop]=mysql_fetch_assoc(mysql_query("SELECT `id`,`name`,`surname` FROM `users_info` where `id`='{$search}'"));
$loop++;
}
Почему не работает?
+156
$query = "INSERT INTO news (title, img_url, subtitle, content, date, time, id)
VALUES (\"" .
$_POST["title"] . "\", \"" .
$_POST["img_url"] . "\", \"" .
$_POST["subtitle"] . "\", \"" .
$_POST["content"] . "\", \"" .
date("Y-m-d") . "\", \"" .
time() . "\", " .
DEFAULT . ");";
только начал php. уверень, есть решение поэлегантнее этого