A large proportion of the computers in this world manipulate money, so it’s always puzzled me that money isn’t actually a first class data type in any mainstream programming language. The lack of a type causes problems, the most obvious surrounding currencies. If all your calculations are done in a single currency, this isn’t a huge problem, but once you involve multiple currencies you want to avoid adding your dollars to your yen without taking the currency differences into account. The more subtle problem is with rounding. Monetary calculations are often rounded to the smallest currency unit. When you do this it’s easy to lose pennies (or your local equivalent) because of rounding errors.
Implement a reusable Money class in PHP, using all the best practices and taking care of all the subtle intricacies of handling money.
ini_set('pcre.backtrack_limit', 10000000); // Лимит обратных ссылок
class Foo
{
public $quux;
}
class Bar
{
private $quux;
public function setQuux(Quux $quux)
{
$this->quux = $quux;
}
}
class Quux
{
}
$foo = new Foo();
$foo->quux = 'text'; // Work
$foo = new Bar();
$foo->quux = 'text'; // Member has private access
class Foo
{
public Quux $quux;
}
Closing the API allows design flaws to be found more easily and gives you the opportunity to evolve your code by creating well defined extension points.
CREATE TRIGGER `after_update_table_name` AFTER UPDATE ON `table_name`
FOR EACH ROW BEGIN
IF `OLD`.`field_name` <> `NEW`.`field_name` THEN
# Your action
END IF;
END
$str = strtr('"%foo" "%bar" "%baz"', [
'%foo' => 'foo',
'%bar' => 'bar',
'%baz' => 'baz',
]);
$n = 10;
$var1 = 1;
$var3 = 1;
$var5 = 1;
$sum = 0;
for ($i=1; $i <= $n; $i++){
if (isset(${"var$i"}))
{
$sum += ${"var$i"};
}
}
echo $sum; // 3
$vars = [];
$zwvola = 1;
$wuvola = 1;
$zwvola = 1; // дубликат
$duvola = 1;
$wdvola = 1;
foreach (get_defined_vars() as $name => $value)
{
if (is_int($value)){
$vars[$name] = $value;
}
}
echo array_sum($vars); // 4
extension=dom.so
class Bar {
/**
* @var Foo[]
*/
public array $prop = [];
}
ini_set('default_socket_timeout', 10);
$options = stream_context_create([
'http' =>
[
'timeout' => 10
]
]);
$content = file_get_contents('http://example.com', false, $options);
utf8
в MySQL - это псевдоним для utf8mb3
(3-байтовое кодирование). Для полноценной работы UTF-8
(4-байтовое кодирование) в MYSQL 5.5 добавлена кодировка utf8mb4
. NOTE: you should not just strip, but replace with replacement character U+FFFD to avoid unicode attacks, mostly XSS:
unicode.org/reports/tr36/#Deletion_of_Noncharacterspreg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value);
$params = array(
'chat_id' => 'YOUR CHAT_ID',
'text' => 'YOUR MESSAGE TEXT',
'reply_markup' => json_encode(array(
'keyboard' => array(
array(
array(
'text' => 'YOUR BUTTON LABEL TEXT',
'url' => 'YOUR BUTTON URL',
),
)),
'one_time_keyboard' => TRUE,
'resize_keyboard' => TRUE,
)),
);
Экземпляр класса Runkit_Sandbox создает отдельный поток основного процесса с собственным окружением и выделенной областью памяти (стеком). С помощью дополнительных параметров конструктора можно ограничивать функционал интерпретатора в песочнице, создавая таким образом безопасное окружение для выполнения пользовательского кода.
$options = array(
'safe_mode'=>true,
'open_basedir'=>'/var/www/users/jdoe/',
'allow_url_fopen'=>'false',
'disable_functions'=>'exec,shell_exec,passthru,system',
'disable_classes'=>'myAppClass',
);
$sandbox = new Runkit_Sandbox($options);
$sandbox->ini_set('html_errors', true);
// ...
$sandbox->eval('var_dump(isset($foo));');
DirectorySlash Off
RewriteCond %{REQUEST_URI} ^.*[^/]$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}/index.php -f
RewriteRule ^(.*)$ /$1/index.php [L]