{"id":286795,"date":"2017-05-24T14:45:08","date_gmt":"2017-05-24T10:45:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=286795"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=286795","title":{"rendered":"\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0432 \u0441\u0442\u0430\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 PHP"},"content":{"rendered":"<p>tl;dr \u0412\u043a\u0440\u0430\u0442\u0446\u0435, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0432 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 PHP \u043c\u043b\u0430\u0434\u0448\u0435 5.6 (\u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 5.4), \u0438 \u0447\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044e \u044d\u0442\u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u0432 PHP \u0432\u0435\u0440\u0441\u0438\u0438 \u0441\u0442\u0430\u0440\u0448\u0435 7.0<\/h3>\n<p>  PHP \u0432\u0435\u0440\u0441\u0438\u0438 &lt; 7 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043f\u0438\u0441\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e: \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u043b, \u0442\u043e \u0438 \u043f\u0440\u0438\u0448\u043b\u043e; \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u043b, \u0442\u043e \u0438 \u0432\u044b\u0448\u043b\u043e.<\/p>\n<pre><code class=\"php\">public function filterArray(array $arr, string $filterParameter, callable $filterCallback) : array<\/code><\/pre>\n<p>  \u041d\u0430\u0434\u043e \u043d\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0451 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u2013 \u0432\u0437\u044f\u043b\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0432 \u043d\u0435\u0439 \u0441\u0432\u043e\u0451 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438. \u0410 \u0432 <i>filterArray()<\/i> \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 <i>$arr<\/i>, \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u043d\u0430\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432, \u0430 \u043d\u0435 integer \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <i>$filterParameter<\/i> \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u043d\u0435 string, \u0430 object, \u043d\u0430\u043c PHP \u043c\u0438\u0433\u043e\u043c \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430. \u041c\u043e\u043b, \u043c\u044b \u0441\u0438\u0451 \u043d\u0435 \u0437\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438.<\/p>\n<h3>\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u0432 PHP \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043b\u0430\u0434\u0448\u0435 5.6<\/h3>\n<p>  \u0410 \u0432\u043e\u0442 PHP \u0432\u0435\u0440\u0441\u0438\u0438 &lt; 5.6 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u044f\u0432\u043d\u043e\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"php\"> public function sortArray($arr, $filterParam) : array \/\/ &lt;- \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 {     \/\/ ... } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 PHP &lt; 5.6 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <i>integer<\/i>, <i>string<\/i>, <i>float<\/i>. <\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0438\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044f\u0437\u044b\u043a\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0442\u0438\u043f\u0430 <i>array<\/i>, <i>object<\/i>, \u043b\u0438\u0431\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"php\"> \/**  * Class ArrayForSorting  * \u0411\u0443\u0434\u0435\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 \u043a\u0443\u0447\u0435\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u0432\u0430\u0436\u043d\u044b.  *\/ class ArrayForSorting {     \/**      * \u041c\u0430\u0441\u0441\u0438\u0432 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.      *       * @var array      *\/     public $arrayForSorting;          \/**      * @construct      *\/     public function __construct($arrayForSorting)     {         $this-&gt;arrayForSorting = $arrayForSorting;     } }  \/**  * Class UserSortArray  * \u041a\u043b\u0430\u0441\u0441, \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0430\u0437\u0434\u0438\u0447\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432: \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u0441\u043b\u0438\u044f\u043d\u0438\u044f, \u043f\u0443\u0437\u044b\u0440\u044c\u043a\u0430.  *\/ class UserSortArray {     \/**      * \u0414\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.      *       * @var object      *\/     public $availableSortingMethods;          \/**      * \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0432\u0441\u0442\u0430\u0432\u043a\u0438.      *       * @param ArrayForSorting $sortArray \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.      *       * @throws UserSortArrayException \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435.      *\/     public function insertSort(ArrayForSorting &$sortArray)     {         if (false === isset($availableSortMethods-&gt;insertMethod)) {             throw new UserSortArrayException('Insert method for user array sort is not available.');         }                  return uasort($sortArray-&gt;arrayForSorting, $availableSortMethods-&gt;bubbleMethod);     } } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h3>\n<p>  \u041d\u043e, \u0438\u0437\u0432\u043e\u043b\u044c\u0442\u0435. \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435 array, \u0430, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, double?<\/p>\n<p>  \u0418 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0445\u043e\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443, \u0445\u043e\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432, \u0445\u043e\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0435?<\/p>\n<p>  \u0412\u044b\u0445\u043e\u0434 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439: \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c.<\/p>\n<pre><code class=\"php\"> class ArraySorter {     public function sortArray(array &$sortArray, $userCallback)     {         \/\/ \u0434\u0430\u0431\u044b \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0442\u044c \u0441\u0432\u044f\u0442\u044b \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430,          \/\/ \u0431\u0443\u0434\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438,          \/\/ \u0430 \u043d\u0435 false \u0438\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c -1.         if (false === $this-&gt;validateArray($sortArray)) {             return [];          }                  return uasort($sortArray, $userCallback);     }          private function validateArray($array)     {         if (!isset($array) || false === is_array($array)) {             return false;         }                  return true;     } } <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e \u0434\u0430\u0436\u0435 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434, \u0441\u0432\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0430\u043c: <\/p>\n<pre><code class=\"php\"> if (null !== $param && '' !== $param) {     return false; \/\/ \u0438\u043b\u0438 [], \u0438\u043b\u0438 '', \u0438\u043b\u0438 \u0447\u0442\u043e \u0435\u0449\u0451 \u043d\u0430\u0434\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432     \/\/ \u043b\u0438\u0431\u043e     throw new Exception(__CLASS__ . __FUNCTION__ . &quot;: Expected integer, got sting&quot;); } <\/code><\/pre>\n<p>  \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2013 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 \u0432 \u0442\u0440\u0435\u0439\u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435 \u0442\u043e\u0442 \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f, \u043f\u0430\u0440\u0441\u0435\u0440 \u0442\u0443\u0442 \u0436\u0435 \u0431\u0440\u043e\u0441\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\u042f\u0437\u044b\u043a \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0417\u0430\u0442\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u041e\u041e\u041f \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u043f\u043e\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043a\u0443\u0434\u0430 \u043f\u043e\u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c;<\/li>\n<li>\u0414\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u043a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e\u2026 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0439\u0442 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c;<\/li>\n<li>\u041d\u043e\u0432\u044b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c, \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432;<\/li>\n<\/ul>\n<p>  \u0422\u0440\u0435\u0439\u0442\u044b \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u0432\u043e\u0435\u0439 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 protected-\u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u043f\u043b\u0430\u043d\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d. \u041d\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0442\u0440\u0435\u0439\u0442\u043e\u0432 \u0432 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<p>  \u0422\u0440\u0435\u0439\u0442\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 PHP, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 5.4.0.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u0435\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a \u0442\u0440\u0435\u0439\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\u0417.\u042b. \u042f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0442\u0440\u0435\u0439\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f integer-\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c <i>maxValue<\/i>, <i>minValue<\/i>, <i>isNatural<\/i>, \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c <i>length<\/i> \u0432\u043c\u0435\u0441\u0442\u043e <i>emptiness<\/i> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.  <\/p>\n<pre><code class=\"php\"> &lt;?php  namespace traits;  \/**  * Trait Validator  * \u0422\u0440\u0435\u0439\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.  *\/ trait Validator {     \/**      * \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.      *      * @param array $validationParams \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.      * \u0424\u043e\u0440\u043c\u0430\u0442 : '\u0442\u0438\u043f' =&gt; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.       * \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0442\u0438\u043f\u0430 \u0438\u0434\u0451\u0442 \u0441\u043b\u043e\u0432\u043e 'not_empty' -- \u0438\u0434\u0451\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443       * (\u0442.\u0435. \u043c\u0430\u0441\u0441\u0438\u0432, \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0438\u043b\u0438 \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430).      * \u0412 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:      * [      *     'integer'          =&gt; 123,      *     'string not_empty' =&gt; 'hello world!',      *     'array'            =&gt; [ ... ],      * ]      *      * @return bool true \u0435\u0441\u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e.      *      * @throws \\Exception \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d.      *\/     public function validate($validationParams)     {         foreach ($validationParams as $type =&gt; $value) {             $methodName = 'validate' . ucfirst($type); \/\/ \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 validateInteger              $isEmptinessValidation = false;             if ('not_empty' === substr($type, -9)) {                 $methodName = 'validate' . ucfirst(substr($type, 0, -9));                 $isEmptinessValidation = true;             }              if (false === method_exists($this, $methodName)) {                 throw new \\Exception(&quot;Trait 'Validator' does not have method '{$methodName}'.&quot;);             }                          \/\/ \u041b\u0438\u0431\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true, \u043b\u0438\u0431\u043e \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445.             $this-&gt;{$methodName}($value, $isEmptinessValidation);         }          return true;     }      \/**      * \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443.      *      * @param string $string               \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430.      * @param bool $isValidateForEmptiness \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443.      *      * @return bool \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.      *\/     public function validateString($string, $isValidateForEmptiness)     {         $validationRules = is_string($string) && $this-&gt;validateForSetAndEmptiness($string, $isValidateForEmptiness);                  if (false === $validationRules) {             $this-&gt;throwError('string', gettype($string));         }          return true;     }      \/**      * \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u0431\u0443\u043b\u0435\u0432\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.      *      * @param boolean $bool \u0431\u0443\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f.      *      * @return bool \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.      *\/     public function validateBoolean($boolean, $isValidateForEmptiness = false)     {         $validationRules = isset($boolean) && is_bool($boolean);          if (false === $validationRules) {             $this-&gt;throwError('boolean', gettype($boolean));         }          return true;     }      \/**      * \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432.      *      * @param string $array                \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432.      * @param bool $isValidateForEmptiness \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443.      *      * @return bool \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.      *\/     public function validateArray($array, $isValidateForEmptiness)     {         $validationRules = is_array($array) && $this-&gt;validateForSetAndEmptiness($array, $isValidateForEmptiness);          if (false === $validationRules) {             $this-&gt;throwError('array', gettype($array));         }          return true;     }      \/**      * \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442.      *      * @param string $object               \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.      * @param bool $isValidateForEmptiness \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443.      *      * @return bool \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.      *\/     public function validateObject($object, $isValidateForEmptiness)     {         $validationRules = is_object($object) && $this-&gt;validateForSetAndEmptiness($object, $isValidateForEmptiness);                  if (false === $validationRules) {             $this-&gt;throwError('object', gettype($object));         }                  return true;     }      \/**      * \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.      *      * @param string $integer              \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.      * @param bool $isValidateForEmptiness \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443.      *      * @return bool \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.      *\/     public function validateInteger($integer, $isValidateForEmptiness)     {         $validationRules = is_int($integer) && $this-&gt;validateForSetAndEmptiness($integer, false);                  if (false === $validationRules) {             $this-&gt;throwError('integer', gettype($integer));         }          return true;     }      \/**      * \u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043d\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0430 \u0442\u043e, \u043f\u0443\u0441\u0442\u043e\u0439 \u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440.      *      * @param string $parameter            \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440.      * @param bool $isValidateForEmptiness \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 (\u043e\u0431\u044a\u0435\u043a\u0442, \u043c\u0430\u0441\u0441\u0438\u0432, \u0441\u0442\u0440\u043e\u043a\u0443) \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0442\u0443.      *      * @return bool \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.      *\/     private function validateForSetAndEmptiness($parameter, $isValidateForEmptiness)     {         $isNotEmpty = true;         if (true === $isValidateForEmptiness) {            $isNotEmpty = false === empty($parameter);          }          return isset($parameter) && true === $isNotEmpty;     }      \/**      * \u0411\u0440\u043e\u0441\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.      *       * @param string $expectedType      * @param string $gotType      *      * @throws \\Exception \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.      *\/     private function throwError($expectedType, $gotType)     {         $validatorMethodName = ucfirst($expectedType) . 'Validator'; \/\/ integer -&gt; IntegerValidator                  throw new \\Exception(&quot;Parse error: {$validatorMethodName} expected type {$expectedType}, got {$gotType}&quot;);     } }  <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Pen (\u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0447\u0435\u0440\u043d\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0443\u0447\u043a\u0430, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0430\u044f\u0441\u044f \u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0447\u0435\u0440\u043d\u0438\u043b), \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0438\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043b\u0430\u0441\u0441 Pen<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\"> &lt;?php  namespace models;  use traits;  \/**  * Class Pen  * \u041e\u0431\u044b\u0447\u043d\u0430\u044f \u0447\u0435\u0440\u043d\u0438\u043b\u044c\u043d\u0430\u044f \u0440\u0443\u0447\u043a\u0430.  *\/ class Pen {     use \\traits\\Validator;      \/**      * \u041e\u0441\u0442\u0430\u0432\u0448\u0435\u0435\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0435\u0440\u043d\u0438\u043b \u0440\u0443\u0447\u043a\u0438.      *      * @var double      *\/     private $remainingAmountOfInk;      \/**      * @construct      *\/     public function __construct()     {         $this-&gt;remainingAmountOfInk = 100;     }      \/**      * \u0412\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.      *      * @param string $message \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.      *       * @return void      *      * @throws ValidatorException \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.      *\/     public function drawMessage($message)     {         $this-&gt;validate([             'string' =&gt; $message,         ]);                  if (0 &gt; $this-&gt;remainingAmountOfInk) {             echo 'Ink ended'; \/\/ \u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c \u0447\u0435\u0440\u043d\u0438\u043b\u0430         }                  echo 'Pen writes message: ' . $message . '&lt;br&gt;' . PHP_EOL;          $this-&gt;remainingAmountOfInk -= 1;     }          \/**      * \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0435\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0435\u0440\u043d\u0438\u043b.      *      * @return integer      *\/     public function getRemainingAmountOfInk()     {         $this-&gt;validate([             'double' =&gt; $this-&gt;remainingAmountOfInk,         ]);          return $this-&gt;remainingAmountOfInk;     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448\u0443 \u0440\u0443\u0447\u043a\u0443 \u043d\u0430 \u0441\u0442\u043e\u043b\u0435: \u00abHello World\u00bb!<\/p>\n<pre><code class=\"php\"> &lt;?php  $sep = DIRECTORY_SEPARATOR; $dir = dirname(__FILE__); \/\/ \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0442\u0440\u0435\u0439\u0442. include_once(&quot;{$dir}{$sep}traits{$sep}Validator.php&quot;);  \/\/ \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0440\u0435\u0439\u0442. include_once(&quot;{$dir}{$sep}models{$sep}Pen.php&quot;);  use models as m;  $pen = new m\\Pen(); $pen-&gt;drawMessage('hi habrahabr'); \/\/ Pen writes message: hi habrahabr  $message = [     'message' =&gt; 'hi im message inside array', ];  try {     $pen-&gt;drawMessage($message); \/\/ \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 ValidatorException } catch (\\Exception $e) {     echo 'exception was throwed during validation of message &lt;br&gt;' . PHP_EOL; } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0412\u043e\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0442\u0440\u0435\u0439\u0442\u0430 \u043c\u043e\u0436\u043d\u043e <s>\u0438\u0437 \u0441\u043b\u043e\u043d\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0438-\u0448\u0430\u0440\u043f<\/s> \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435\/\u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u0435\u0437 \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043d\u0433\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445.<\/p>\n<p>  \u042f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0441\u0442\u0430\u043b \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u043a \u043c\u0435\u0442\u043e\u0434\u0443 <i>validate()<\/i> \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043e\u0441\u043e\u0431\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u0438\u0435, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435\/\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 double-\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043a\u043e\u043b\u0431\u044d\u043a\u0438 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0432\u044b\u0432\u043e\u0434 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. <\/p>\n<p>  \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u044b\u043b\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430, \u0435\u0441\u0442\u044c \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043e\u043d\u0430 \u0434\u0430\u0436\u0435 \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 PHP.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/329360\/\"> https:\/\/habrahabr.ru\/post\/329360\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>tl;dr \u0412\u043a\u0440\u0430\u0442\u0446\u0435, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0432 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 PHP \u043c\u043b\u0430\u0434\u0448\u0435 5.6 (\u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 5.4), \u0438 \u0447\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044e \u044d\u0442\u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-286795","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=286795"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286795\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}