{"id":211683,"date":"2014-04-19T00:01:02","date_gmt":"2014-04-18T20:01:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=211683"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=211683","title":{"rendered":"<span class=\"post_title\">PHP_Over: \u0438\u043c\u0438\u0442\u0430\u0442\u043e\u0440 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043e\u043a<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/e9b\/2a4\/8aa\/e9b2a48aaabf870e9db8176943df4b7f.jpg\" alt=\"image\"\/>  <\/p>\n<blockquote><p>\u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0432\u0443\u043c \u0440\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0438\u043c\u0435\u043d\u0430.<\/p><\/blockquote>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c<\/h1>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0444\u0438\u0433\u0443\u0440:  <\/p>\n<ul>\n<li>\u043a\u0443\u0431<\/li>\n<li>\u0448\u0430\u0440<\/li>\n<li>\u0446\u0438\u043b\u0438\u043d\u0434\u0440<\/li>\n<li>\u043a\u043e\u043d\u0443\u0441<\/li>\n<li>\u043f\u0438\u0440\u0430\u043c\u0438\u0434\u0430<\/li>\n<li>\u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0435\u043f\u0438\u043f\u0435\u0434<\/li>\n<\/ul>\n<pre><code class=\"php\">\/\/ \u041e\u0431\u044a\u0435\u043c \u043a\u0443\u0431\u0430 function Volume_Cube(\/*int*\/ $side) {     return pow($side, 3); }  \/\/ \u041e\u0431\u044a\u0435\u043c \u0448\u0430\u0440\u0430 function Volume_Sphere(\/*double*\/ $radius) {     return ((4\/3) * M_PI * pow($radius, 3)); }  \/\/ \u041e\u0431\u044a\u0435\u043c \u0446\u0438\u043b\u0438\u043d\u0434\u0440\u0430 function Volume_Cylinder(\/*double*\/ $radius, \/*int*\/ $height) {     return (M_PI * pow($radius, 2) * $height); }  \/\/ \u041e\u0431\u044a\u0435\u043c \u043a\u043e\u043d\u0443\u0441\u0430 function Volume_\u0421one(\/*int*\/ $height, \/*double*\/ $radius) {     return ((1\/3) * M_PI * pow($radius, 2) * $height); }  \/\/ \u041e\u0431\u044a\u0435\u043c \u043f\u0438\u0440\u0430\u043c\u0438\u0434\u044b function Volume_Pyramid(\/*int*\/ $square, \/*int*\/ $height) {     return ((1\/3) * $square * $height); }  \/\/ \u041e\u0431\u044a\u0435\u043c \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0435\u043f\u0438\u043f\u0435\u0434\u0430 function Volume_Cuboid(\/*int*\/ $length, \/*int*\/ $width, \/*int*\/ $height) {     return ($length * $width * $height); } <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u043e\u043d\u0430 \u0435\u0441\u0442\u044c \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043f\u0440\u0438 \u043e\u0434\u043d\u0438\u0445 \u0438 \u0442\u0435\u0445 \u0436\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445 (\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043c\u0430) \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u0448\u0435\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e.<\/p>\n<p>  <b>PHP_Over<\/b> \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0438\/\u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0442\u0438\u043f\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u0430.<\/p>\n<pre><code class=\"php\">require 'src\/php_over\/PHP_Over.php';  $Volume = new PHP_Over; $Volume     -&gt;overload('%i',         function($side)     {         return pow($side, 3);     })     -&gt;overload('%d',         function($radius)     {         return ((4 \/ 3) * M_PI * pow($radius, 3));     })     -&gt;overload('%d', '%i',         function($radius, $height)     {         return (M_PI * pow($radius, 2) * $height);     })     -&gt;overload('%i', '%d',         function($height, $radius)     {         return ((1 \/ 3) * M_PI * pow($radius, 2) * $height);     })     -&gt;overload('%i', '%i',         function($square, $height)     {         return ((1 \/ 3) * $square * $height);     })     -&gt;overload('%i', '%i', '%i',         function($length, $width, $height)     {         return ($length * $width * $height);     });  $Volume(5);        \/\/ 125 $Volume(5.);       \/\/ 523.5987755983 $Volume(3., 10);   \/\/ 282.74333882308 $Volume(10, 2.);   \/\/ 41.887902047864 $Volume(15, 9);    \/\/ 45 $Volume(15, 9, 3); \/\/ 405 <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0438\u043c\u044f <b><code>$Volume<\/code><\/b>, \u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043c\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0439 \u0444\u0438\u0433\u0443\u0440\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438 \u0442\u0435 \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f.<\/p>\n<h1>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c<\/h1>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0444\u0438\u0433\u0443\u0440 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043c:<\/p>\n<ul>\n<li><s><b>\u043a\u0443\u0431<\/b><\/s><\/li>\n<li>\u0448\u0430\u0440<\/li>\n<li>\u0446\u0438\u043b\u0438\u043d\u0434\u0440<\/li>\n<li>\u043a\u043e\u043d\u0443\u0441<\/li>\n<li><s><b>\u043f\u0438\u0440\u0430\u043c\u0438\u0434\u0430<\/b><\/s><\/li>\n<li>\u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0435\u043f\u0438\u043f\u0435\u0434<\/li>\n<li><b>\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0442\u0440\u0430\u044d\u0434\u0440<\/b><\/li>\n<li><b>\u043f\u0440\u0438\u0437\u043c\u0430<\/b><\/li>\n<\/ul>\n<pre><code class=\"php\">\/\/ ... Part 1  $Volume     -&gt;override('%i',         function($edge)     {         return (pow($edge, 3) * sqrt(2) \/ 12);     })     -&gt;override('%i', '%i',         function($square, $height)     {         return ($square * $height);     });  $Volume-&gt;invokeTo(5);        \/\/ 14.73139127472 $Volume-&gt;invokeTo(5.);       \/\/ 523.5987755983 $Volume-&gt;invokeTo(3., 10);   \/\/ 282.74333882308 $Volume-&gt;invokeTo(10, 2.);   \/\/ 41.887902047864 $Volume-&gt;invokeTo(15, 9);    \/\/ 135 $Volume-&gt;invokeTo(15, 9, 3); \/\/ 405 <\/code><\/pre>\n<h1>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c<\/h1>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0442\u0440\u0430\u044d\u0434\u0440<\/li>\n<li><b><s>\u0448\u0430\u0440<\/s><\/b><\/li>\n<li><b><s>\u0446\u0438\u043b\u0438\u043d\u0434\u0440<\/s><\/b><\/li>\n<li><b><s>\u043a\u043e\u043d\u0443\u0441<\/s><\/b><\/li>\n<li>\u043f\u0440\u0438\u0437\u043c\u0430<\/li>\n<li>\u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0435\u043f\u0438\u043f\u0435\u0434<\/li>\n<\/ul>\n<pre><code class=\"php\">\/\/ ... Part 1 \/\/ ... Part 2  $Volume     -&gt;override('%i', '%d')     -&gt;override('%d', false);  function wrapperToVolume() {     global $Volume;      try {         return $Volume-&gt;invokeArgsTo(func_get_args());     } catch (Exception $exp) {         return $exp-&gt;getMessage();     } }  wrapperToVolume(5);         \/\/ 14.73139127472 wrapperToVolume(5.);        \/\/ \u0412\u044b\u0437\u043e\u0432 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u043d\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 wrapperToVolume(3., 10);    \/\/ \u0412\u044b\u0437\u043e\u0432 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u043d\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 wrapperToVolume(10, 2.);    \/\/ \u0412\u044b\u0437\u043e\u0432 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u043d\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 wrapperToVolume(15, 9);     \/\/ 135 wrapperToVolume(15, 9, 3);  \/\/ 405 <\/code><\/pre>\n<p>  <\/p>\n<hr\/>\n<p>  \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0441\u0435\u0432\u0434\u043e-\u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0430\u043c\u043e \u0441\u043e\u0431\u043e\u0439, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u0430\u0432\u043e \u0436\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435\u0433\u043e:<\/p>\n<pre><code class=\"php\">require 'src\/php_over\/PHP_Over.php';  define('NUMBER_OF_OPERATIONS_TEST_PHP_OVER', 1000000);  $array1 = array('a' =&gt; 'green', 'b' =&gt; 'brown', 'c' =&gt; 'blue', 'red'); $array2 = array('a' =&gt; 'green', 'b' =&gt; 'yellow', 'blue', 'red');  function my_array_intersect_assoc($array1, $array2) {     return array_intersect_assoc($array1, $array2); }  $php_over = new PHP_Over; $php_over-&gt;overload('%a', '%a', 'my_array_intersect_assoc');  function Test_1() {     global $array1, $array2;      $i = 0;     $t = microtime(true);     while ($i++ &lt; NUMBER_OF_OPERATIONS_TEST_PHP_OVER) {         array_intersect_assoc($array1, $array2);     }      return (microtime(true) - $t); }  function Test_2() {     global $array1, $array2;      $i = 0;     $t = microtime(true);     while ($i++ &lt; NUMBER_OF_OPERATIONS_TEST_PHP_OVER) {         my_array_intersect_assoc($array1, $array2);     }      return (microtime(true) - $t); }  function Test_3() {     global $php_over, $array1, $array2;      $i = 0;     $t = microtime(true);     while ($i++ &lt; NUMBER_OF_OPERATIONS_TEST_PHP_OVER) {         $php_over-&gt;invokeTo($array1, $array2);     }      return (microtime(true) - $t); }  \/\/========================================================================== \/\/        | Count | PHP 5.3(average) | PHP 5.4(average) | PHP 5.5(average) | \/\/========================================================================== \/\/ Test_1 |   5   |     6.56 sec     |     5.86 ses     |     5.69 sec     | \/\/========================================================================== \/\/ Test_2 |   5   |    11.11 sec     |    10.02 sec     |     9.51 sec     | \/\/========================================================================== \/\/ Test_3 |   5   |   148.6 sec      |   123.6 sec      |   115.4 sec      | \/\/========================================================================== <\/code><\/pre>\n<p>  <\/p>\n<hr\/>\n<p>  <b>.git: <\/b><a href=\"https:\/\/github.com\/lubaev\/PHP_Over\">PHP_Over<\/a>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/211683\/\"> http:\/\/habrahabr.ru\/post\/211683\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/e9b\/2a4\/8aa\/e9b2a48aaabf870e9db8176943df4b7f.jpg\" alt=\"image\"\/>  <\/p>\n<blockquote><p>\u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0432\u0443\u043c \u0440\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0438\u043c\u0435\u043d\u0430.<\/p><\/blockquote>\n<p>  <\/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-211683","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/211683","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=211683"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/211683\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}