This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. | |
Было: | |
use Framework\Module\Foo; | |
use Framework\Module\Bar; | |
use Framework\Module\Baz; | |
В PHP 7 можно написать: | |
use Framework\Module\{Foo, Bar, Baz}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Comparison operators | |
<?php | |
$a = 5; // 5 as an integer | |
var_dump($a == 5); // compare value; return true | |
var_dump($a == '5'); // compare value (ignore type); return true | |
var_dump($a === 5); // compare type/value (integer vs. integer); return true | |
var_dump($a === '5'); // compare type/value (integer vs. string); return false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$raw = '22. 11. 1968'; | |
$start = DateTime::createFromFormat('d. m. Y', $raw); | |
echo 'Start date: ' . $start->format('Y-m-d') . "\n"; | |
<?php | |
// create a copy of $start and add one month and 6 days | |
$end = clone $start; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. UTF-8 at the PHP level | |
mb_strpos() and mb_strlen() | |
mb_internal_encoding() | |
the mb_http_output() | |
<?php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pdo = new PDO('sqlite:/path/db/users.db'); | |
$stmt = $pdo->prepare('SELECT name FROM users WHERE id = :id'); | |
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); // <-- filter your data first (see [Data Filtering](#data_filtering)), especially important for INSERT, UPDATE, etc. | |
$stmt->bindParam(':id', $id, PDO::PARAM_INT); // <-- Automatically sanitized for SQL by PDO | |
$stmt->execute(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. | |
Свойство может быть | |
доступным извне: public | |
доступным только в этом классе: private | |
доступным в классе и всех его наследника: | |
protected | |
Такие же модификаторы доступа могут | |
иметь и методы класса | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'password.php'; | |
$passwordHash = password_hash('secret-password', PASSWORD_DEFAULT); | |
if (password_verify('bad-password', $passwordHash)) { | |
//Правильный пароль | |
} else { | |
//Неправильный пароль | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Исключения | |
Исключение – это исключительная ситуация, о которой мы | |
предполагаем, что она может произойти | |
Исключение – это объект специального класса, наследника | |
класса Exception | |
Исключение может быть «выброшено» оператором throw | |
Исключение после «выбрасывания» начинает «всплывать» | |
вверх по иерархии кода, пока не встретится блок try … catch | |
В этом блоке исключение можно «поймать» и предпринять | |
какие-то действия |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Описание регулиярных выражений: | |
* исходная строка'Hello, world! how are you?' | |
* . - любой символ | |
* .* - любой символ повторяющийся бесконечное число раз | |
* (.*) - захват подстроки в $1...$N | |
* i - не чувствительна к регистру -- '/hello,/i' | |
* [\s] - пробельный символ -- '/hello,[\s]/i' | |
* ^ - начало строки (якорь начала) -- '/^hello,[\s]/i' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$arrFilter = | |
array( | |
[ | |
"LOGIC" => "OR", | |
["ID" => 85416], | |
["ID" => 86535], | |
] | |
) |