1. PHP / Говнокод #24812

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    class MyBigClass
    {
        var $allocatedSize;
        var $allMyOtherStuff;
    }
    
    function AllocateMyBigClass()
    {
        $before = memory_get_usage();
        $ret = new MyBigClass;
        $after = memory_get_usage();
        $ret->allocatedSize = ($after - $before);
    
        return $ret;
    }

    Зачем нам в языке адекватный sizeof, у нас нет времени, чтобы ебаться с ним!

    Подробнее: https://stackoverflow.com/questions/1351855/getting-size-in-memory-of-an-object-in-php

    gost, 25 Сентября 2018

    Комментарии (25)
  2. PHP / Говнокод #24811

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    /**
     * Cast an object into a different class.
     *
     * Currently this only supports casting DOWN the inheritance chain,
     * that is, an object may only be cast into a class if that class 
     * is a descendant of the object's current class.
     *
     * This is mostly to avoid potentially losing data by casting across
     * incompatable classes.
     *
     * @param object $object The object to cast.
     * @param string $class The class to cast the object into.
     * @return object
     */
    function cast($object, $class) {
    	if( !is_object($object) ) 
    		throw new InvalidArgumentException('$object must be an object.');
    	if( !is_string($class) )
    		throw new InvalidArgumentException('$class must be a string.');
    	if( !class_exists($class) )
    		throw new InvalidArgumentException(sprintf('Unknown class: %s.', $class));
    	if( !is_subclass_of($class, get_class($object)) ) 
    		throw new InvalidArgumentException(sprintf(
    			'%s is not a descendant of $object class: %s.',
    			$class, get_class($object)
    		));
    	/**
    	 * This is a beautifully ugly hack.
    	 *
    	 * First, we serialize our object, which turns it into a string, allowing
    	 * us to muck about with it using standard string manipulation methods.
    	 *
    	 * Then, we use preg_replace to change it's defined type to the class
    	 * we're casting it to, and then serialize the string back into an
    	 * object.
    	 */
    	return unserialize(
    		preg_replace(
    			'/^O:\d+:"[^"]++"/', 
    			'O:'.strlen($class).':"'.$class.'"',
    			serialize($object)
    		)
    	);
    }

    Это прекрасно.

    gost, 25 Сентября 2018

    Комментарии (7)
  3. PHP / Говнокод #24800

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    // CVE-2012-5692
    
    /* 4015. */        static public function get($name) 
    /* 4016. */        { 
    /* 4017. */            // Check internal data first 
    /* 4018. */            if ( isset( self::$_cookiesSet[ $name ] ) ) 
    /* 4019. */            { 
    /* 4020. */                return self::$_cookiesSet[ $name ]; 
    /* 4021. */            } 
    /* 4022. */            else if ( isset( $_COOKIE[ipsRegistry::$settings['cookie_id'].$name] ) ) 
    /* 4023. */            { 
    /* 4024. */                $_value = $_COOKIE[ ipsRegistry::$settings['cookie_id'].$name ]; 
    /* 4025. */    
    /* 4026. */                if ( substr( $_value, 0, 2 ) == 'a:' ) 
    /* 4027. */                { 
    /* 4028. */                    return unserialize( stripslashes( urldecode( $_value ) ) ); 
    /* 4029. */                } 
    
    /*  
    The vulnerability is caused due to this method unserialize user input passed through cookies without a proper 
    sanitization. The only one check is done at line 4026,  where is controlled that the serialized string starts 
    with 'a:',  but this is not  sufficient to prevent a  "PHP Object Injection"  because an attacker may send  a 
    serialized string which represents an array of objects.  This can be  exploited to execute arbitrary PHP code 
    via the  "__destruct()" method of the  "dbMain" class,  which calls the "writeDebugLog" method to write debug 
    info into a file.  PHP code may  be injected  only through the  $_SERVER['QUERY_STRING']  variable,  for this 
    reason successful exploitation of this vulnerability requires short_open_tag to be enabled. 
    */

    Если вы думаете, что самое плохое, что ждёт ваш уютный сайт на «PHP» — это Роберт-брось-таблицу, то вы глубоко ошибаетесь.

    CSRF verification passed.

    gost, 23 Сентября 2018

    Комментарии (45)
  4. PHP / Говнокод #24785

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $data = new stdClass();
      $data->receivers_list = [];
      $data->receivers_list[0] = new stdClass();
      $data->receivers_list[0]->address = $user_wallet;
      $data->receivers_list[0]->amount = $amount;

    Кусок кода, от проекта, который мне теперь надо поддерживать.

    spacel0rd, 18 Сентября 2018

    Комментарии (8)
  5. PHP / Говнокод #24772

    −6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    Name: 
    <input type="text" name=
                                                             "name" 
    value="<?php echo $name;?>">
    
    E-mail: <
    
                         input type="text" 
    name="email" value="<?php 
    echo $email;?>">
    
    Website: <input type="text" name="website" value="
    <?php echo $website;?>"
    
                                                                                  >
    
    Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
    
    Gender:
    <input type="radio" name="gender"
    <
    ?
    php 
    
    
    if (isset($gender) && $gender=="female") echo "checked";
    
    ?>            value="female">Female
    
    <input type="radio" name="gender"
    <?php if (isset($gender) && $gender=="male") echo "checked";?>
    value="male">
    
                  Male
    
    <input type="radio" name="gender"
    
    <?php if (isset($gender) && $gender=="other") echo "checked";?>value="other">Other

    PHP говно

    Ksyrx, 16 Сентября 2018

    Комментарии (3)
  6. PHP / Говнокод #24740

    +1

    1. 1
    2. 2
    3. 3
    <?php
    echo implode ("<br>", file("govnokod.php"));
    ?>

    Угадайте как называется это!

    Arduino, 10 Сентября 2018

    Комментарии (1)
  7. PHP / Говнокод #24689

    −1

    1. 1
    define('DIR', pathinfo($_SERVER['SCRIPT_FILENAME'], PATHINFO_DIRNAME) . '/');

    phpMASTER666, 30 Августа 2018

    Комментарии (0)
  8. PHP / Говнокод #24686

    −6

    1. 1
    2. 2
    $haystack
    $needle

    Что за тупые названия аргументов?

    guestinxo, 30 Августа 2018

    Комментарии (13)
  9. PHP / Говнокод #24685

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    /**
     * Class Iin
     * @package App\Classes\Support
     *
     * Класс проверки иин для казахстана
     *
     * ИИН содержит 12 цифр из которых
     * первые 6 цифр - дата рождения [гг-мм-дд]
     * 7-я цифра - пол и век (нечетные цифры - муж, четные женский)
     *      1,2 - 19 век
     *      3,4 - 20 век
     *      5,6 - 21 век
     *      7,8,9,0 - зарезирвированны на будущее
     * 8 - 11 регистрационный гос номер
     * и 12 - контрольный разряд
     *
     * Иин проверяесться по контрольной сумме через две последовательности
     * Сперва каждая цифра иин, кроме последней умножается на цифру из 1-й последовательности и суммируется
     * Результат делиться на 11 и если он от 0 до 9 и соотвествует 12-й цифре иин то иин верен,
     * если результат 0 - иин не верен, если результат 10 - то проверка продолжается по второй последовательности
     * Если результат проверки по всторой последовательности от 1 до 9 и равен 12-й цифре иин - то иин верен иначе проверка
     * заканчивается и иин не верный.
     *
     * UPD - Хьюстон у нас проблемы - некоторые безответственные работники цонов делают неверные иин с 7,8 и 9 цифрой для 22 и 23 века.
     * В итоге люди для системы как из 23 века а сами из 21 или 20 - так что пока не настал 22 и 23 век их разряды будут для 20 века.
     * Не люблю костыли но работники цонов такие работники - а менеджеры и клиенты недовольны, так что придеться
     *

    https://habr.com/company/ua-hosting/blog/420091/

    guestinxo, 29 Августа 2018

    Комментарии (1)
  10. PHP / Говнокод #24648

    −1

    1. 1
    2. 2
    $query  = "SELECT * FROM archivo_mhora WHERE id_aparato=" . $aparatos_row->id;
    $query .= " && DATE_FORMAT(fecha, '%Y.%m.%d')='" . date('Y.m.d', $cur_fecha) . "' ORDER BY energy";

    Я не знаю, к какой секции следует отнести этот высер:
    1) Автор решил учить испанский. Таблицы имеют имена `aparatos`, `abonandos`, etc
    2) Само собой, SQL injection
    3) Порнография при работе с датой

    kai, 23 Августа 2018

    Комментарии (3)