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

    −2

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

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

    JPHP, 04 Октября 2018

    Комментарии (9)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)