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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    <?php
    if (isset($block4_items_block) || count($block4_items_block) >= 3 || (isset($block4_items_block[0]['bg']) || isset($block4_items_block[1]['bg']) || isset($block4_items_block[2]['bg'])) || (isset($block4_items_block[0]['title']) || isset($block4_items_block[1]['title']) || isset($block4_items_block[2]['title'])) || (strlen($block4_items_block[0]['bg']) > 0 || strlen($block4_items_block[1]['bg']) > 0  || strlen($block4_items_block[2]['bg']) > 0 ) || (strlen($block4_items_block[0]['title']) > 0 || strlen($block4_items_block[1]['title']) > 0  || strlen($block4_items_block[2]['title']) > 0 )){
    
    ?>

    Прислал друг.
    Примерно такое же условие еще находится в шаблоне.

    StTv, 15 Октября 2018

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

    −3

    1. 1
    $keys = array_keys(array_flip($keys));

    Малая доля индусского кода

    kgk, 14 Октября 2018

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static function findById($id)
        {
            $model = self::where('id', $id)->get();
    
            $count = $model->getIterator()->count();
            if($count > 0) {
                return $model->getIterator()->current();
            }
    
            return false;
        }

    Laravel Eloquent Model

    pb92, 11 Октября 2018

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

    −2

    1. 1
    2. 2
    PHP + Java = JPHP
    https://habr.com/post/425223/

    Поэтому я за "JPHP".

    JPHP, 04 Октября 2018

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

    −3

    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
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    require_once $_SERVER['DOCUMENT_ROOT'] . '/models/core/class.Application.php';
    require_once 'class.DatabaseConnect.php';
    require_once 'class.DatabaseResult.php';
    
    class DatabaseQuery extends Application {
    
        private $m_db_connect = NULL; //Соединение с БД
        private $m_query_statment = NULL; //Результат последнего запроса
        private $m_construct_query = NULL; //Строка формирования запроса
    
        public function __construct(DatabaseConnect $db_connect) {
            $this->m_db_connect = $db_connect;
        }
        
        public function __destruct() {
            $this->m_db_connect = null;
        }
    
        //Вставляет данные в таблицу
        public function insert($data) {
            if (count($data) === 0)
                return false;
            $query_list = [];
            //Обход таблиц
            foreach ($data as $t_name => $table) {
    
                //Ассациативный массив даннвх, где ключ массива это имя колонки в БД
                $column_list = [];
                //Копируем данные в отдельный массив	
                foreach ($table as $c_name => $column)
                    $column_list[$c_name] = $column;
                //Строка запроса
                $query = "INSERT INTO {$t_name} (" . implode(', ', array_keys($column_list)) . ') VALUES ';
                //Выпоняем обход
                for ($i = 0; $i < count($column_list[array_keys($column_list)[0]]); $i++) {
                    $query_values = '(';
                    //
                    foreach ($column_list as $c_name => $column)
                        $query_values .= '\'' . $column_list[$c_name][$i] . '\',';
    
                    $query_values = chop($query_values, ',') . '),';
                    $query .= $query_values;
                }
                $query_list[] = chop($query, ',');
            }
    
            try {
                for ($i = 0; $i < count($query_list); $i++) {
                    $result = $this->query($query_list[$i]);
                }
            } catch (PDOException $e) {
                Application::handlerErrorDB($e);
                return false;
            }
    
            return true;
        }
    
        public function setSelect($data = ['*']) {
            $query = 'SELECT ';
            foreach ($data as $v)
                $query .= $v . ',';
            $this->m_construct_query = chop($query, ',') . ' ';
            return $this;
        }
    
        public function setDelete($tables = []) {
            $query = 'DELETE ';
            foreach ($tables as $v)
                $query .= $v . ',';
            $this->m_construct_query = chop($query, ',') . ' ';
            return $this;
        }
    
        public function setUpdate($tables) {
            $query = 'UPDATE ';
            foreach ($tables as $v)
                $query .= $v . ',';
            $this->m_construct_query = chop($query, ',') . ' ';
            return $this;
        }
    
        public function setSet($data) {
            $query = 'SET ';
            foreach ($data as $k => $v)
                $query .= "$k = '$v',";
            $this->m_construct_query .= chop($query, ',') . ' ';
            return $this;
        }
    
        public function setFrom($tables) {
            $query = 'FROM ';
            foreach ($tables as $v)
                $query .= $v . ',';
            $this->m_construct_query .= chop($query, ',') . ' ';
            return $this;
        }
    
        ...

    Вот что бывает когда у тебя юношеский максимализм - ты пытаешь написать свой фреймворк, и при этом это твой первый проект на PHP.

    C3-PO, 03 Октября 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Страйкер удалил политоту, а какого хуя ты не удалил
    
    http://govnokod.ru/user/25102/codes
    http://govnokod.ru/user/21529
    http://govnokod.ru/user/21528/codes
    
    И другую гомосятину в разделе "VisualBasic"?

    Perevedi_na_PHP, 29 Сентября 2018

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

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $price = WC()->cart->get_product_price( $_product );
    $price = str_replace('<span class="woocommerce-Price-amount amount">', '', $price);
    $price = str_replace(' <span class="woocommerce-Price-currencySymbol"><span class="rur">р<span>уб.</span></span></span></span>', '', $price);
    
    $price = str_replace(',', '', $price);
    $price = str_replace(' ', '', $price);
    $price = str_replace('.', '', $price);
    $price_m2 = round($price/25.2);
    echo '<span class="woocommerce-Price-amount amount">'.$price_m2.' <span class="woocommerce-Price-currencySymbol"><span class="rur">р<span>уб.</span></span></span></span><span class="awspn_price_note"> / м<sup>2</sup></span>';

    Привет, меня зовут Вася!
    Как-то раз на одном из сайтов с WooCommerce мне нужно было в корзине вывести цену листового товара за метр квадратный. Ну а че, листа размера не 25.2м2 не существует, а еще на php.net я прочитал про функцию str_replace. И так сойдет! :)

    Vasya_Kostylkov, 27 Сентября 2018

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

    −4

    1. 1
    2. 2
    3. 3
    <?php
     
    --"";

    PHP Parse error: syntax error, unexpected ';', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /home/XQ5b1K/prog.php on line 3

    https://ideone.com/vYLgSF

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

    Комментарии (9)
  9. 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)
  10. 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)