{"id":259952,"date":"2015-06-23T17:44:02","date_gmt":"2015-06-23T13:44:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=259952"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=259952","title":{"rendered":"PHP extension. \u041f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 Traversable \u0438 ArrayAccess"},"content":{"rendered":"<p>     \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b Traversable \u0438 ArrayAccess.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0441\u044b\u043b\u043e\u043a.  <\/p>\n<ul>\n<li><a href=\"http:\/\/lxr.php.net\/\">lxr.php.net<\/a> \u2014 \u0423\u0434\u043e\u0431\u043d\u0435\u0439\u0448\u0438\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 php;<\/li>\n<li><a href=\"http:\/\/www.phpinternalsbook.com\/\">phpinternalsbook<\/a> \u2014 \u041f\u043e\u043b\u0435\u0437\u043d\u0435\u0439\u0448\u0438\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u043f\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c php. \u0410 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u043e <a href=\"http:\/\/www.phpinternalsbook.com\/classes_objects.html\">\u043a\u043b\u0430\u0441\u0441\u0430\u043c<\/a>;<\/li>\n<li><a href=\"https:\/\/php.net\/manual\/ru\/internals2.php\">\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u044f\u0434\u0440\u0443 PHP<\/a>.<\/li>\n<\/ul>\n<p>  \u0418 \u043f\u0440\u043e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443: \u044f \u043f\u0438\u0441\u0430\u043b \u043a\u043e\u0434 \u043f\u043e ubuntu, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 linux \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u043e\u0432 (\u0434\u0430 \u0438 OS X) \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 (\u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c apt-get). \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434 Windows, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445 (<s>\u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043f\u0438\u0448\u0435\u0442 \u043a\u043e\u0434 \u043f\u043e windows<\/s>).<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h3>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c PHP<\/h3>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0431\u0435\u0440\u0435\u043c debug-\u0432\u0435\u0440\u0441\u0438\u044e PHP. \u041c\u043e\u0436\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0438 \u0441 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439, \u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u043f\u0430\u0440\u044b debug-\u0444\u043b\u0430\u0433\u043e\u0432 PHP \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0433\u043e\u0432\u043e\u0440\u0447\u0438\u0432\u0435\u0439.<\/p>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u0438\u0434\u0435\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u0442\u044f\u043d\u0443\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 PHP (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 ~\/dev\/c\/) \u0438 \u0431\u0435\u0440\u0435\u043c \u043a\u043e\u0434 php \u0438\u0437 git-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.  <\/p>\n<pre><code class=\"bash\">git clone http:\/\/git.php.net\/repository\/php-src.git cd php-src <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u0432\u0435\u0436\u0443\u044e \u0432\u0435\u0442\u043a\u0443.  <\/p>\n<pre><code class=\"bash\">git checkout PHP-5.6 <\/code><\/pre>\n<p>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 PHP \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (\u0441\u043a\u043e\u0440\u0435\u0439 \u0432\u0441\u0435\u0433\u043e \u043e\u043d\u0438 \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c).  <\/p>\n<pre><code class=\"bash\">sudo apt-get install build-essential autoconf automake libtool <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c bison. \u0412 ubuntu \u0441 14 \u0432\u0435\u0440\u0441\u0438\u0438 \u0438\u0434\u0435\u0442 bison \u0438\u0434\u0435\u0442 \u0432\u0435\u0440\u0441\u0438\u0438 3 \u0438 \u0432\u044b\u0448\u0435, \u043a\u043e\u0442\u043e\u0440\u0443\u044e PHP \u043d\u0435 \u043f\u0435\u0440\u0435\u0432\u0430\u0440\u0438\u0432\u0430\u0435\u0442. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u044f 2.7.  <\/p>\n<pre><code class=\"bash\">wget http:\/\/launchpadlibrarian.net\/140087283\/libbison-dev_2.7.1.dfsg-1_amd64.deb wget http:\/\/launchpadlibrarian.net\/140087282\/bison_2.7.1.dfsg-1_amd64.deb  sudo dpkg -i libbison-dev_2.7.1.dfsg-1_amd64.deb sudo dpkg -i bison_2.7.1.dfsg-1_amd64.deb <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e \u0431\u0435\u0437 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043d\u0430\u043c libxml2 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f. \u0418\u043d\u0430\u0447\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c libxml2-dev.  <\/p>\n<pre><code class=\"bash\">sudo apt-get install libxml2-dev <\/code><\/pre>\n<p>  Configure \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 debug-\u0432\u0435\u0440\u0441\u0438\u044f, \u0431\u0435\u0437 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439. \u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 &#8212;prefix \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d PHP.   <\/p>\n<pre><code class=\"bash\">.\/buildconf .\/configure --disable-all --enable-debug --prefix=$HOME\/dev\/bin\/php make && make install <\/code><\/pre>\n<p>  \u041e\u043a\u0435, PHP \u0433\u043e\u0442\u043e\u0432. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0432\u0435\u0436\u0435\u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0439 php c \u0444\u043b\u0430\u0433\u043e\u043c -v \u0438 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u043c\u044b \u0442\u043e \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0438 \u043a\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u043e (\u0430 \u0442\u043e \u043c\u0430\u043b\u043e \u043b\u0438).  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/php -v <\/code><\/pre>\n<h3>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u00ab\u0421\u043a\u0435\u043b\u0435\u0442\u00bb \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <b>ext_skel<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0436\u0438\u0442 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438 PHP. \u041c\u044b \u043e\u0442 ext_skel \u043e\u0442\u043a\u0430\u0436\u0435\u043c\u0441\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e .gitignore \u043e\u043d \u043d\u0430\u043f\u0438\u0445\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0442\u043d\u0438 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0432 \u0432 \u0444\u0430\u0439\u043b\u044b. \u0410 .gitignore \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c <a href=\"https:\/\/raw.githubusercontent.com\/ArenSH\/php_jco\/master\/.gitignore\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f ext_skel, \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438: \u0432 &#8212;extname \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u0430 \u0432 &#8212;skel \u043f\u0443\u0442\u044c \u0434\u043e \u043f\u0430\u043f\u043a\u0438 skeleton.  <\/p>\n<pre><code class=\"bash\">~\/dev\/c\/php-src\/ext\/ext_skel --extname=jco --skel=$HOME\/dev\/c\/php-src\/ext\/skeleton\/ <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435, \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438.  <\/p>\n<pre><code class=\"bash\">jco\/     .gitignore     config.m4     config.w32     jco.c     php_jco.h <\/code><\/pre>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c config.m4 \u0438 \u043f\u0438\u0448\u0435\u043c:  <\/p>\n<pre><code class=\"cmake\">if test &quot;$PHP_JCO&quot; = &quot;yes&quot;; then   AC_DEFINE(HAVE_JCO, 1, [Whether you have Jco])   PHP_NEW_EXTENSION(jco, jco.c, $ext_shared) fi <\/code><\/pre>\n<p>  \u0412\u0441\u0435, \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 config.m4 \u0431\u0443\u0434\u0435\u043c \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0441 PHP_NEW_EXTENSION, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0442\u0443\u0434\u0430 \u043d\u043e\u0432\u044b\u0435 \u0444\u0430\u0439\u043b\u044b.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f: php_jco.h. \u041d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e php_%\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f%.h  <\/p>\n<pre><code>#ifndef PHP_JCO_H #define PHP_JCO_H 1  extern zend_module_entry jco_module_entry; #define phpext_jco_ptr &jco_module_entry  \/\/\u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u043e-\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b. #ifdef ZTS #include &quot;TSRM.h&quot; #endif  #endif <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0438\u043f\u0430 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_modules.h#_zend_module_entry\">zend_module_entry<\/a> \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043d\u0430\u0448\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0438. \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <i>\u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c<\/i> \u0432\u0438\u0434\u0430 %\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f%_module_entry. <\/p>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c jco.c \u0438 \u043f\u0438\u0448\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u0449\u0435\u0435.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>#ifdef HAVE_CONFIG_H #include &quot;config.h&quot; #endif  #include &quot;php.h&quot; #include &quot;php_jco.h&quot;  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e  PHP_FUNCTION(hello_from_jco) {     \/\/ \u0412\u0442\u043e\u0440\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.     RETURN_STRING(&quot;JCO ENABLED! YEY!&quot;, 1); }  \/\/ \u0414\u0430\u0434\u0438\u043c PHP \u0437\u043d\u0430\u0442\u044c \u043e \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0443\u043a\u0430\u0437\u0430\u0432 \u0435\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044f. const zend_function_entry jco_functions[] = {     PHP_FE(hello_from_jco,  NULL)     PHP_FE_END };  \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e php \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f PHP_MINIT_FUNCTION(jco_init) {     return SUCCESS; }   zend_module_entry jco_module_entry = {     STANDARD_MODULE_HEADER,     &quot;jco&quot;, \/\/ \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f     jco_functions,     PHP_MINIT(jco_init),     NULL, \/\/ MSHUTDOWN     NULL, \/\/ RINIT     NULL, \/\/ RSHUTDOWN     NULL, \/\/ MINFO     &quot;0.1&quot;, \/\/\u0432\u0435\u0440\u0441\u0438\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f     STANDARD_MODULE_PROPERTIES };  #ifdef COMPILE_DL_JCO ZEND_GET_MODULE(jco) #endif <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043d\u0430\u0448\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0438\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043b\u0438, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 NULL`\u0430\u043c\u0438). \u0410 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.h#135\">ZEND_GET_MODULE<\/a> \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e get_module, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e jco_module_entry;<\/p>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043d\u0430\u0448\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c phpize, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0430\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0438 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u043e\u0432 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f (we need to go deeper!)  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/phpize <\/code><\/pre>\n<p>  \u0418 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435. \u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 &#8212;with-php-config \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u0434\u043e \u0444\u0430\u0439\u043b\u0430 php-config \u0441\u043e\u0431\u0440\u0430\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 debug-\u0432\u0435\u0440\u0441\u0438\u0438 PHP  <\/p>\n<pre><code class=\"bash\">.\/configure --with-php-config=$HOME\/dev\/bin\/php\/bin\/php-config make && make install <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0441\u043e\u0431\u0440\u0430\u043b\u043e\u0441\u044c \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a, \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c php \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c (\u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u043f\u0440\u0430\u0432\u0438\u043c \u0438 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c).  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/php -dextension=jco.so --r &quot;hello_from_jco();&quot; JCO ENABLED! YEY! <\/code><\/pre>\n<h3>\u041a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e zval \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h3>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u043a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 PHP \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438 PHP_FUNCTION, PHP_NAMED_FUNCTION \u0438\u043b\u0438 PHP_METHOD. \u0420\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u043d\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.  <\/p>\n<pre><code>void prefix_name(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used void ***tsrm_ls) <\/code><\/pre>\n<p>  \u0413\u0434\u0435   <\/p>\n<ul>\n<li>ht \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u044b\u0437\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/li>\n<li>return_value \u2014 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/li>\n<li>return_value_ptr \u2014 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435)<\/li>\n<li>this_ptr \u2014 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434<\/li>\n<li>return_value_is_used \u2014 \u0444\u043b\u0430\u0433, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043b\u0438 \u0434\u0430\u043b\u0435\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f<\/li>\n<li>tsrm_ls \u2014 Thread Safe Resourse Manager Local Storage! \u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0430<\/li>\n<\/ul>\n<p>  \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 ZEND_ARG_INFO_*.  <\/p>\n<pre><code>\/\/\u0438\u043c\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, _, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u0441\u044b\u043b\u043a\u0430, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 1) \/\/\u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u0438\u043c\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 ZEND_ARG_INFO(0, var1) ZEND_ARG_INFO(0, var2) ZEND_END_ARG_INFO()  \/* \u041c\u0430\u043a\u0440\u043e\u0441\u044b \u043e\u0442\u0434\u0430\u0434\u0443\u0442 \u043d\u0430\u043c static const zend_arg_info arginfo_construct[] = {                                                                            { NULL, 0, NULL, 2, 0, 0, 0, 0 },     { &quot;var1&quot;, sizeof(&quot;var1&quot;)-1, NULL, 0, 0, 0, 0, 0 },     { &quot;var2&quot;, sizeof(&quot;var2&quot;)-1, NULL, 0, 0, 0, 0, 0 }, } *\/ <\/code><\/pre>\n<p>  <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.h#ZEND_BEGIN_ARG_INFO_EX\">ZEND_BEGIN_ARG_INFO_EX<\/a>, <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.h#ZEND_ARG_INFO\">ZEND_ARG_INFO<\/a> \u0438 ZEND_END_ARG_INFO \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0434\u0430\u0434\u0443\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_compile.h#_zend_arg_info\">zend_arg_info<\/a>. \u041f\u0440\u0438\u0447\u0435\u043c, \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0442\u0438\u043f\u0443 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_compile.h#_zend_internal_function_info\">zend_internal_function_info<\/a>. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438 \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0435\u0439 \u0443 \u043d\u0438\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435, \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u043a\u043e\u0441\u043e\u0432 PHP_FE, PHP_ME, PHP_ME_MAPPING, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044f\/\u043a\u043b\u0430\u0441\u0441\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0442\u0438\u043f\u0430 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.h#_zend_function_entry\">zend_function_entry<\/a>.  <\/p>\n<pre><code>typedef struct _zend_function_entry {     const char *fname; \/\/ \u0418\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u0432 PHP     void (*handler)(INTERNAL_FUNCTION_PARAMETERS); \/\/\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e     const struct _zend_arg_info *arg_info; \/\/\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0430\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432     zend_uint num_args; \/\/ \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 arg_info)     zend_uint flags; \/\/ \u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u043b\u0430\u0433\u0438 } zend_function_entry <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (function_table). \u041f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.c#zend_parse_parameters\">zend_parse_parameters<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.  <\/p>\n<ul>\n<li>num_args \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/li>\n<li>tsrm_ls \u2014 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u044b\u0448\u0435<\/li>\n<li>type_spec \u2014 \u0441\u0442\u0440\u043e\u043a\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/li>\n<li>\u2026 \u2014 \u0434\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b<\/li>\n<\/ul>\n<p>  \u041f\u0440\u043e zend_parse_parameters \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/php.net\/manual\/en\/internals2.funcs.php\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 PHP \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend.h#_zval_struct\">zval<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0430\u043c\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend.h#_zvalue_value\">zvalue_value<\/a>, \u0435\u0433\u043e \u0442\u0438\u043f, \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u0438 \u0444\u043b\u0430\u0433, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u043c\u0435\u043d\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.  <\/p>\n<pre><code>struct _zval_struct {     \/* Variable information *\/     zvalue_value value;     \/* value *\/     zend_uint refcount__gc;     zend_uchar type;    \/* active type *\/     zend_uchar is_ref__gc; }; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 zval \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441\u044b <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_gc.h#ALLOC_ZVAL\">ALLOC_ZVAL<\/a> (\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c), <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend.h#MAKE_STD_ZVAL\">MAKE_STD_ZVAL<\/a>(ALLOC_ZVAL + \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439) \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>  \u0414\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e zval ALLOC_ZVAL \u0432\u044b\u0434\u0435\u043b\u0438\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0434 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_gc.h#_zval_gc_info\">_zval_gc_info<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f zval \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_execute.h#i_zval_ptr_dtor\">zval_ptr_dtor<\/a>. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_variables.h#_zval_dtor\">zval_dtor<\/a>, zval_ptr_dtor \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 zval \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e.<\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e zvalue_value \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0447\u0438\u0441\u043b\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u0418 \u043f\u043e\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0434\u0432\u0430 zval \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0442\u043e \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0445 \u043d\u0438\u0445 \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e zval \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"http:\/\/www.phpinternalsbook.com\/zvals.html\">phpintenralsbook<\/a>. \u0410 \u043f\u0440\u043e \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0432 <a href=\"http:\/\/php.net\/manual\/ru\/features.gc.collecting-cycles.php\">\u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043f\u043e PHP<\/a>.<\/p>\n<h3>\u041a\u043b\u0430\u0441\u0441\u044b<\/h3>\n<p>  \u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044e \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b jco_darray.h \u0438 \u043f\u0438\u0448\u0435\u043c \u0442\u0443\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435.  <\/p>\n<pre><code>#ifndef PHP_JCO_DARRAY_H #define PHP_JCO_DARRAY_H 1  extern zend_class_entry *jco_darray_ce;  void jco_darray_init(TSRMLS_D);  #endif <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u043e\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e jco_darray_ce \u0442\u0438\u043f\u0430 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend.h#_zend_class_entry\">zend_class_entry<\/a> \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b jco_darray.\u0441.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco_darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>#include &quot;php.h&quot; #include &quot;jco_darray.h&quot;  zend_class_entry *jco_darray_ce;  PHP_METHOD(jco_darray, sayHello) {     RETURN_STRING(&quot;Hello from darray!&quot;, 1); }  const zend_function_entry jco_darray_functions[] = {     \/\/ \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, arginfo, \u0444\u043b\u0430\u0433\u0438     PHP_ME(jco_darray, sayHello, NULL, ZEND_ACC_PUBLIC)     PHP_FE_END };  void jco_darray_init(TSRMLS_D) {     zend_class_entry tmp_ce;     INIT_CLASS_ENTRY(tmp_ce, &quot;JCO\\\\DArray&quot;, jco_darray_functions);      jco_darray_ce = zend_register_internal_class(&tmp_ce TSRMLS_CC);      return; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f jco_darray_init. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 tmp_ce \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.h#INIT_CLASS_ENTRY\">INIT_CLASS_ENTRY<\/a>. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0438\u0437 PHP, <i>\u0432\u043a\u043b\u044e\u0447\u0430\u044f namespace<\/i>.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.c#do_register_internal_class\">zend_register_internal_class<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (class_table).<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 jco_darray_init \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e jco_init (\u0444\u0430\u0439\u043b jco.h).  <\/p>\n<pre><code>PHP_MINIT_FUNCTION(jco_init) {     jco_darray_init(TSRMLS_C);     return SUCCESS; } <\/code><\/pre>\n<p>  \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b jco_darray.c \u0432 config.m4 (\u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u0439\u043b\u043e\u0432 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0411\u0415\u0417 \u0437\u0430\u043f\u044f\u0442\u044b\u0445).  <\/p>\n<pre><code class=\"cmake\">PHP_NEW_EXTENSION(jco, jco.c jco_darray.c, $ext_shared) <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 config.m4, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0440\u0430\u0437 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c phpize  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/phpize --clean ~\/dev\/bin\/php\/bin\/phpize   .\/configure --with-php-config=$HOME\/dev\/bin\/php\/bin\/php-config make && make install <\/code><\/pre>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0435\u043c php \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e: jco.php)  <\/p>\n<pre><code class=\"php\">&lt;?php $darray = new \\JCO\\DArray(); echo $darray-&gt;sayHello() . PHP_EOL;  ?&gt; <\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u043d\u0430\u0448\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/php -dextension=jco.so jco.php <\/code><\/pre>\n<h3>D for Dynamic<\/h3>\n<p>  \u0421 \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0438 \u0443\u043c\u0435\u0435\u0442, \u0447\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u00abHello\u00bb, \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0443\u0435\u0434\u0435\u0448\u044c. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043e\u043d \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0441\u044f \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432. \u0412\u0440\u0435\u043c\u044f \u0432\u0437\u044f\u0442\u044c \u0438 \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e ds \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0443\u0434\u0430 \u0444\u0430\u0439\u043b darray.h, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">ds\/drray.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>#ifndef PHP_JCO_DS_DARRAY_H #define PHP_JCO_DS_DARRAY_H 1  #include &quot;php.h&quot;  typedef  struct jco_ds_darray {     size_t count; \/\/ \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435NULL\u0435\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432     size_t length; \/\/ \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430     size_t min_length; \/\/ \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430     size_t capacity; \/\/ \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c - \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440     void *elements; \/\/ \u043c\u0430\u0441\u0441\u0438\u0432 \u0435\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (zval) } jco_ds_darray;  jco_ds_darray *jco_ds_darray_create(size_t size, size_t capacity); void jco_ds_darray_destroy(jco_ds_darray *array);  #define jco_ds_darray_length(array) ((array)-&gt;length) #define jco_ds_darray_min_length(array) ((array)-&gt;min_length) #define jco_ds_darray_capacity(array) ((array)-&gt;capacity) #define jco_ds_darray_count(array) ((array)-&gt;count) #define jco_ds_darray_first(array) ((zval *)(array)-&gt;elements)  #endif <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u0444\u0430\u0439\u043b\u0435 ds\/darray.c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">ds\/darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>#include &quot;ds\/darray.h&quot; #include &quot;php.h&quot;  jco_ds_darray *jco_ds_darray_create(size_t size, size_t capacity) {     jco_ds_darray *array = emalloc(sizeof(jco_ds_darray));     if (!array) {         return NULL;     }      array-&gt;count = 0;     array-&gt;length = 0;     array-&gt;min_length = size;     array-&gt;capacity = capacity;     array-&gt;elements = NULL;       return array; }   void jco_ds_darray_destroy(jco_ds_darray *array) {     if (!array) {         return;     }      efree(array); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432, \u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0445 \u043a\u0430\u043a-\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u044f\u0441\u043d\u0438\u043c \u043a\u0430\u043a php \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 zval) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 zend_object_value, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f.  <\/p>\n<pre><code>typedef struct _zend_object_value {     zend_object_handle handle;     const zend_object_handlers *handlers; } zend_object_value; <\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>handlers \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 php \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0435\u043b\u0430\u0435\u043c \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c (\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0438 \u0442.\u043f.). \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u043f\u0440\u043e <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_object_handlers.h#_zend_object_handlers\">zend_object_handlers<\/a> \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.  <\/li>\n<li>handle \u2014 \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0439 int, \u00abid\u00bb \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 object_store. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 php \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend.h#zend_object\">zend_object<\/a> \u0432 object_store \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 handle. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_API.c#1190\">\u0435\u0441\u043b\u0438 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f create_object<\/a>, \u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f zend_object \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043d\u0430. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u043f\u0440\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"http:\/\/www.phpinternalsbook.com\/classes_objects\/custom_object_storage.html\">php internals book<\/a><\/li>\n<\/ul>\n<p>  \u0418\u0442\u0430\u043a, \u0432\u0441\u0435 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u2014 \u044d\u0442\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 zend_object. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e create_object \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0434 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0445 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f jco_darray_ce.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco_darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code> zend_object_handlers jco_darray_handlers;  typedef struct jco_darray {     zend_object std;     jco_ds_darray *array; } jco_darray;  static void jco_darray_free_object_storage(jco_darray *intern TSRMLS_DC) {     zend_object_std_dtor(&intern-&gt;std TSRMLS_CC);      if (intern-&gt;array) {         jco_ds_darray_destroy(intern-&gt;array);     }      efree(intern); }  zend_object_value jco_darray_create_object(zend_class_entry *class_type TSRMLS_DC) {     zend_object_value retval;      jco_darray *intern = emalloc(sizeof(jco_darray));     memset(intern, 0, sizeof(jco_darray));      \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442: \u0443\u043a\u0430\u0437\u0430\u0432\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441 \u0438 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0447\u0438\u0435 \u043f\u043e\u043b\u044f     zend_object_std_init(&intern-&gt;std, class_type TSRMLS_CC);     \/\/\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442     object_properties_init(&intern-&gt;std, class_type);      \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (object_store)     retval.handle = zend_objects_store_put(         intern,         (zend_objects_store_dtor_t) zend_objects_destroy_object, \/\/ \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430         (zend_objects_free_object_storage_t) jco_darray_free_object_storage, \/\/\u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u043b\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430         NULL \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430         TSRMLS_CC     );      \/\/\u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438-\u043e\u0431\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432     retval.handlers = &jco_darray_handlers;      return retval; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_objects_API.c#zend_objects_store_put\">zend_objects_store_put<\/a> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:  <\/p>\n<ul>\n<li>dtor (<a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_objects.c#zend_objects_destroy_object\">zend_objects_destroy_object<\/a>) \u2014 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f 0, \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430. \u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0442\u0430\u043a \u0436\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (__destruct). \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 php \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0434\u0440\u0443\u0433\u043e\u0433\u043e __destruct \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u043d exit())  <\/li>\n<li>free_storage (<a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_objects.c#zend_objects_free_object_storage\">zend_objects_free_object_storage<\/a>) \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u0434 \u043e\u0431\u044a\u0435\u043a\u0442 (zend_object). \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430: \u043b\u0438\u0431\u043e \u043a\u043e\u0433\u0434\u0430 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f 0, \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430.  <\/li>\n<li>clone \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0438 \u0447\u0442\u043e\u0431\u044b \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_objects_API.c#zend_objects_store_clone_obj\">zend_objects_store_clone_obj<\/a>. \u041d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0437\u0443. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 99% \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0432 clone \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c NULL.  <\/li>\n<\/ul>\n<p>  \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u044e jco_darray_init \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438  <\/p>\n<pre><code>    \/\/\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f zend_object     jco_darray_ce-&gt;create_object = jco_darray_create_object;      \/\/\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043e\u0431\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432     memcpy(&jco_darray_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); <\/code><\/pre>\n<p>  \u0410 \u0433\u0434\u0435 \u0436\u0435 \u043c\u0430\u0441\u0441\u0438\u0432? \u0410 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco_darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>PHP_METHOD(jco_darray, __construct) {     jco_darray *intern;     long size = 0;     long capacity = 0;      zend_error_handling error_handling;      \/\/\u0417\u0430\u043c\u0435\u043d\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0448\u0438\u0431\u043e\u043a \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435     zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);      \/\/\u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (l - long), \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 - \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &quot;ll&quot;, &size, &capacity) == FAILURE) {         zend_restore_error_handling(&error_handling TSRMLS_CC);         return;     }      \/\/ \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0448\u0438\u0431\u043e\u043a     zend_restore_error_handling(&error_handling TSRMLS_CC);      if (size &lt;= 0) {         zend_throw_exception(NULL, &quot;Array size must be positive&quot;, 0 TSRMLS_CC);         return;     }      if (capacity &lt; 0) {         zend_throw_exception(NULL, &quot;Array capacity must be positive or 0&quot;, 0 TSRMLS_CC);         return;     }      \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e handle     intern = zend_object_store_get_object(getThis() TSRMLS_CC);      intern-&gt;array = jco_ds_darray_create((size_t)size, (size_t)capacity);     if (!intern-&gt;array) {         zend_throw_exception(NULL, &quot;Failed to allocate array&quot;, 0 TSRMLS_CC);     }      return; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>,<br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c __construct \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.  <\/p>\n<pre><code> ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 1) \/\/\u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u0438\u043c\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 ZEND_ARG_INFO(0, size) ZEND_ARG_INFO(0, capacity) ZEND_END_ARG_INFO()  const zend_function_entry jco_darray_functions[] = {     PHP_ME(jco_darray, __construct, arginfo_construct, ZEND_ACC_PUBLIC)     PHP_ME(jco_darray, sayHello, arginfo_void, ZEND_ACC_PUBLIC)     PHP_FE_END }; <\/code><\/pre>\n<p>  \u0412\u0440\u0435\u043c\u044f \u0441\u043e\u0431\u0440\u0430\u0442\u044c extension \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c phpize, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f config.m4 (\u041e\u0431\u0435\u0449\u0430\u044e, \u044d\u0442\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437)  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/phpize --clean ~\/dev\/bin\/php\/bin\/phpize  .\/configure --with-php-config=$HOME\/dev\/bin\/php\/bin\/php-config make && make install <\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/php -dextension=jco.so jco.php <\/code><\/pre>\n<h3>ArrayAccess<\/h3>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 ds\/darray.h \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c: get, set, unset (\u0438 clone \u0437\u0430\u043e\u0434\u043d\u043e).  <\/p>\n<pre><code>jco_ds_darray *jco_ds_darray_create(size_t size, size_t capacity); jco_ds_darray *jco_ds_darray_clone(jco_ds_darray *array); void jco_ds_darray_destroy(jco_ds_darray *array); zval *jco_ds_darray_get(jco_ds_darray *array, size_t index); zval *jco_ds_darray_set(jco_ds_darray *array, size_t index, zval *value); void jco_ds_darray_unset(jco_ds_darray *array, size_t index); <\/code><\/pre>\n<p>  \u0418 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">ds\/darray.\u0441<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>    #include &quot;ds\/darray.h&quot; #include &quot;php.h&quot;  #define ELEM_SIZE (sizeof(zval))  \/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0434 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430.  \/\/ \u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d index, \u0442\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043a\u0440\u0430\u0442\u043d\u043e capacity \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e, \/\/ \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f index-\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 static inline int _jco_ds_darray_expand(jco_ds_darray *array, size_t index) {     if (array && array-&gt;capacity &gt; 0) {         size_t capacity = array-&gt;capacity;         size_t max_elements = array-&gt;length;         size_t expand_count;         if (index) {             expand_count = ((index + 1) \/ capacity) * capacity + capacity;         } else {             expand_count = (max_elements + capacity);         }          zval *elements;         if (max_elements == 0 && !array-&gt;elements) {             elements = (zval *)emalloc(ELEM_SIZE * expand_count);         } else {             elements = (zval *)erealloc((void *)array-&gt;elements, ELEM_SIZE * expand_count);         }          if (elements) {             zval *ptr = (elements + max_elements);             memset(ptr, 0, array-&gt;capacity * ELEM_SIZE);              array-&gt;length = expand_count;             array-&gt;elements = elements;              return 1;         }          return 0;     }      return 0; }   jco_ds_darray *jco_ds_darray_create(size_t size, size_t capacity) {     jco_ds_darray *array = emalloc(sizeof(jco_ds_darray));     if (!array) {         return NULL;     }      array-&gt;length = 0;     array-&gt;min_length = size;     array-&gt;capacity = size;     array-&gt;count = 0;     array-&gt;elements = NULL;      if (size &gt; 0 && !_jco_ds_darray_expand(array, 0)) {         efree(array);          return NULL;     }      array-&gt;length = size;     array-&gt;capacity = capacity;      return array; }   void jco_ds_darray_destroy(jco_ds_darray *array) {     if (!array) {         return;     }      if (array-&gt;length &gt; 0) {         zval *elem = (zval *)array-&gt;elements;         while (array-&gt;length--) {             if (elem != NULL && Z_REFCOUNT_P(elem) &gt; 0) {                 zval_dtor(elem);             }             elem++;         }     }      if (array-&gt;elements) {         efree(array-&gt;elements);     }      efree(array); }  jco_ds_darray *jco_ds_darray_clone(jco_ds_darray *array) {     if (!array) {         return NULL;     }      jco_ds_darray *new_array = emalloc(sizeof(jco_ds_darray));     if (!new_array) {         return NULL;     }      new_array-&gt;count = array-&gt;count;     new_array-&gt;length = array-&gt;length;     new_array-&gt;min_length = array-&gt;min_length;     new_array-&gt;capacity = array-&gt;capacity;     new_array-&gt;elements = (zval *)emalloc(ELEM_SIZE * array-&gt;length);     if (!new_array-&gt;elements) {         efree(new_array);          return NULL;     }      memcpy(new_array-&gt;elements, array-&gt;elements, ELEM_SIZE * array-&gt;length);     \/\/memcpy \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430\u043c \u0442\u043e\u043b\u044c\u043a\u043e zval`\u044b, \u043d\u043e \u043e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043e\u0434\u043d\u0438 \u0442\u0435 \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f     \/\/\u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 zval_copy_ctor     size_t index;     for (index = 0; index &lt; array-&gt;length; index++) {         zval *elem = (zval *)new_array-&gt;elements + index;         if (elem != NULL && Z_REFCOUNT_P(elem) &gt; 0) {             zval_copy_ctor(elem);         }     }        return new_array;  }   zval *jco_ds_darray_get(jco_ds_darray *array, size_t index) {     if (!array || array-&gt;length &lt; (index + 1)) {         return NULL;     }      zval *elem = (zval *)(array-&gt;elements) + index;     if (!elem || Z_TYPE_P(elem) == IS_NULL) {         return NULL;     }      \/\/\u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e is_ref__gc = 0     Z_UNSET_ISREF_P(elem);     return elem; }   void jco_ds_darray_unset(jco_ds_darray *array, size_t index) {     if (!array || array-&gt;length &lt; (index + 1)) {         return;     }      zval *elem = (zval *)array-&gt;elements + index;     if (elem != NULL && Z_REFCOUNT_P(elem) &gt; 0) {         if (Z_TYPE_P(elem) != IS_NULL) {             array-&gt;count--;         }          zval_dtor(elem);         *elem = (zval) {0};     }  }   zval *jco_ds_darray_set(jco_ds_darray *array, size_t index, zval *value) {     if (!array) {         return;     }      if ((index + 1) &gt; array-&gt;length) {         if (array-&gt;capacity == 0) {             return NULL;         }          if (!_jco_ds_darray_expand(array, index)) {             return NULL;         }     }     zval *elem = (zval *)array-&gt;elements + index;     int prev_is_not_null = 0;     if (Z_REFCOUNT_P(elem) &gt; 0 && Z_TYPE_P(elem)) {         zval_dtor(elem);         prev_is_not_null = 1;     }      elem-&gt;value = value-&gt;value;     elem-&gt;type  = value-&gt;type;     elem-&gt;refcount__gc = 1;     elem-&gt;is_ref__gc = 0;     zval_copy_ctor(elem);      if (prev_is_not_null && Z_TYPE_P(elem) == IS_NULL) {         array-&gt;count--;     }     else if (!prev_is_not_null && Z_TYPE_P(elem) != IS_NULL) {         array-&gt;count++;     }       return elem; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432 jco_ds_darray_set ALLOC_ZVAL \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u0441\u0441\u0438\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u044b\u043b \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u043c\u044b \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0442\u0430\u043a \u0447\u0442\u043e GC \u0431\u0443\u0434\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u043c. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0435\u043d\u043d\u043e \u0438 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c zval_dtor \u0432\u043c\u0435\u0441\u0442\u043e zval_ptr_dtor. <\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ArrayAccess.   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco_darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>    PHP_METHOD(jco_darray, count) {     jco_darray *intern;     long count;      intern = zend_object_store_get_object(getThis() TSRMLS_CC);     count = (long)jco_ds_darray_count(intern-&gt;array);      ZVAL_LONG(return_value, count); }  PHP_METHOD(jco_darray, length) {     jco_darray *intern;     long length;      intern = zend_object_store_get_object(getThis() TSRMLS_CC);     length = (long) jco_ds_darray_length(intern-&gt;array);      ZVAL_LONG(return_value, length); }  PHP_METHOD(jco_darray, offsetSet) {     jco_darray *intern;     zval *val;     long index;       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &quot;lz&quot;, &index, &val) == FAILURE) {         zend_throw_exception(NULL, &quot;Failed to parse arguments&quot;, 0 TSRMLS_CC);         return;     }      intern = zend_object_store_get_object(getThis() TSRMLS_CC);     jco_ds_darray_set(intern-&gt;array, (size_t)index, val);  }  PHP_METHOD(jco_darray, offsetUnset) {     jco_darray *intern;     long index;      if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &quot;l&quot;, &index) == FAILURE) {         zend_throw_exception(NULL, &quot;Invalid index passed&quot;, 0 TSRMLS_CC);         return;     }       intern = zend_object_store_get_object(getThis() TSRMLS_CC);     jco_ds_darray_unset(intern-&gt;array, (size_t)index); }  PHP_METHOD(jco_darray, offsetGet) {     jco_darray *intern;     long index;      if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &quot;l&quot;, &index) == FAILURE) {         zend_throw_exception(NULL, &quot;Invalid index passed&quot;, 0 TSRMLS_CC);         return;     }       intern = zend_object_store_get_object(getThis() TSRMLS_CC);     zval *val = jco_ds_darray_get(intern-&gt;array, (size_t)index);      if (val) {         \/\/\u043d\u0430\u0437\u043d\u0430\u0447\u0438\u043d\u0438\u0435, \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a, \u0432\u044b\u0437\u0432\u0430\u0442\u044c zval_copy_ctor, \u0432\u044b\u0437\u0432\u0430\u0442\u044c zval_ptr_dtor         ZVAL_ZVAL(return_value, val, 1, 0);     } else {         ZVAL_NULL(return_value);     } }  PHP_METHOD(jco_darray, offsetExists) {     jco_darray *intern;     long index;      if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &quot;l&quot;, &index) == FAILURE) {         zend_throw_exception(NULL, &quot;Invalid index passed&quot;, 0 TSRMLS_CC);         return;     }       intern = zend_object_store_get_object(getThis() TSRMLS_CC);     zval *val = jco_ds_darray_get(intern-&gt;array, (size_t)index);     if (val) {         ZVAL_TRUE(return_value);     } else {         ZVAL_FALSE(return_value);     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0430.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco_darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>ZEND_BEGIN_ARG_INFO_EX(arginfo_jco_darray_offset, 0, 0, 1) ZEND_ARG_INFO(0, offset) ZEND_END_ARG_INFO()  ZEND_BEGIN_ARG_INFO_EX(arginfo_jco_darray_offset_value, 0, 0, 2) ZEND_ARG_INFO(0, offset) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO()  const zend_function_entry jco_darray_functions[] = {     PHP_ME(jco_darray, __construct, arginfo_construct, ZEND_ACC_PUBLIC)     PHP_ME(jco_darray, offsetSet, arginfo_jco_darray_offset_value, ZEND_ACC_PUBLIC)     PHP_ME(jco_darray, offsetGet, arginfo_jco_darray_offset, ZEND_ACC_PUBLIC)     PHP_ME(jco_darray, offsetUnset, arginfo_jco_darray_offset, ZEND_ACC_PUBLIC)     PHP_ME(jco_darray, offsetExists, arginfo_jco_darray_offset, ZEND_ACC_PUBLIC)     PHP_ME(jco_darray, count, arginfo_void, ZEND_ACC_PUBLIC)     PHP_ME(jco_darray, length, arginfo_void, ZEND_ACC_PUBLIC)     PHP_FE_END }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0443\u043a\u0430\u0436\u0435\u043c php \u0447\u0442\u043e \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ArrayAccess  <\/p>\n<pre><code>    zend_class_implements(jco_darray_ce TSRMLS_CC, 1, zend_ce_arrayaccess); <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438  \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438 class_entry \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e.<\/p>\n<p>  zend_ce_arrayaccess \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0432 \u0444\u0430\u0439\u043b\u0435 zend_interfaces.h (\u0432\u043c\u0435\u0441\u0442\u0435 \u0441 zend_ce_traversable, zend_ce_aggregate, zend_ce_iterator \u0438 zend_ce_serializable), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u0444\u0430\u0439\u043b jco_darray.c  <\/p>\n<pre><code>#include &quot;php.h&quot; #include &quot;zend_interfaces.h&quot; #include &quot;jco_darray.h&quot; #include &quot;ds\/darray.h&quot; <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0437\u0430\u043e\u0434\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0441 \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c  <\/p>\n<pre><code class=\"php\">&lt;?php ini_set(&quot;memory_limit&quot;, &quot;512M&quot;);  $data = range(1, 500000);  $t1 = microtime(true); $m1 = memory_get_usage();  $jar = new \\JCO\\DArray(500000, 0); foreach($data as $index =&gt; &$val) {     $jar[$index] = $val * 3; }  echo &quot;JCO\\Darray&quot; . PHP_EOL; echo &quot;TIME: &quot; . (microtime(true) - $t1) . PHP_EOL; echo &quot;MEMORY: &quot; . ((memory_get_usage() - $m1)\/1048576) . PHP_EOL; gc_collect_cycles();   $t1 = microtime(true); $m1 = memory_get_usage(); $ar = []; foreach($data as $index =&gt; &$val) {     $ar[$index] = $val * 3; }  echo &quot;AR&quot; . PHP_EOL; echo &quot;TIME: &quot; . (microtime(true) - $t1) . PHP_EOL; echo &quot;MEMORY: &quot; . ((memory_get_usage() - $m1)\/1048576) . PHP_EOL; gc_collect_cycles();  ?&gt; <\/code><\/pre>\n<p>  C\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c php c \u043d\u0430\u0448\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c  <\/p>\n<pre><code class=\"bash\">    make && make install <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/php -dextension=jco.so jco.php  JCO\\Darray TIME: 0.43633484840393 MEMORY: 11.44548034668 Array TIME: 0.3345410823822 MEMORY: 137.51664733887 <\/code><\/pre>\n<p>  \u042d\u0439\u2026 \u041d\u0430\u0448 \u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0439 \u0447\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 php!<\/p>\n<h3>Object Handlers<\/h3>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0442\u0430\u043a\u0438\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043f\u0440\u043e <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_object_handlers.c#std_object_handlers\">object_handlers<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0441\u044f \u0432\u044b\u0448\u0435.  <\/p>\n<pre><code>ZEND_API zend_object_handlers std_object_handlers = {     zend_objects_store_add_ref,             \/* add_ref *\/     zend_objects_store_del_ref,             \/* del_ref *\/     zend_objects_clone_obj,                 \/* clone_obj *\/      zend_std_read_property,                 \/* read_property *\/     zend_std_write_property,                \/* write_property *\/     zend_std_read_dimension,                \/* read_dimension *\/     zend_std_write_dimension,               \/* write_dimension *\/     zend_std_get_property_ptr_ptr,          \/* get_property_ptr_ptr *\/     NULL,                                   \/* get *\/     NULL,                                   \/* set *\/     zend_std_has_property,                  \/* has_property *\/     zend_std_unset_property,                \/* unset_property *\/     zend_std_has_dimension,                 \/* has_dimension *\/     zend_std_unset_dimension,               \/* unset_dimension *\/     zend_std_get_properties,                \/* get_properties *\/     zend_std_get_method,                    \/* get_method *\/     NULL,                                   \/* call_method *\/     zend_std_get_constructor,               \/* get_constructor *\/     zend_std_object_get_class,              \/* get_class_entry *\/     zend_std_object_get_class_name,         \/* get_class_name *\/     zend_std_compare_objects,               \/* compare_objects *\/     zend_std_cast_object_tostring,          \/* cast_object *\/     NULL,                                   \/* count_elements *\/     zend_std_get_debug_info,                \/* get_debug_info *\/     zend_std_get_closure,                   \/* get_closure *\/     zend_std_get_gc,                        \/* get_gc *\/     NULL,                                   \/* do_operation *\/     NULL,                                   \/* compare *\/ }; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043a\u0430\u043a \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: read_dimension, write_dimension, has_dimension \u0438 unset_dimension.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_object_handlers.c#zend_std_read_dimension\">zend_std_read_dimension<\/a>, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ArrayAccess \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 offsetGet. \u0410 \u0432\u044b\u0437\u043e\u0432 php \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0447\u0435\u043c, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c (\u041e\u0427\u0415\u041d\u042c!) \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e.<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e: \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0430 \u0437\u0430\u043e\u0434\u043d\u043e count \u0438 clone).  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco_darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code> \/\/\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 zval \u043a long static inline long zval_to_long(zval *zv) {     if (Z_TYPE_P(zv) == IS_LONG) {         return Z_LVAL_P(zv);     } else {         zval tmp = *zv;         zval_copy_ctor(&tmp);         convert_to_long(&tmp);         return Z_LVAL(tmp);     } }  static zend_object_value jco_darray_clone(zval *object TSRMLS_DC) {     jco_darray *old_object = zend_object_store_get_object(object TSRMLS_CC);      zend_object_value new_object_val = jco_darray_create_object(Z_OBJCE_P(object) TSRMLS_CC);     jco_darray *new_object = zend_object_store_get_object_by_handle(new_object_val.handle TSRMLS_CC);      \/\/\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430     zend_objects_clone_members(         &new_object-&gt;std, new_object_val,         &old_object-&gt;std, Z_OBJ_HANDLE_P(object) TSRMLS_CC     );      new_object-&gt;array = jco_ds_darray_clone(old_object-&gt;array);      if (!new_object-&gt;array) {         zend_throw_exception(NULL, &quot;Failed to clone jco_darray&quot;, 0 TSRMLS_CC);     }      return new_object_val; }    static zval *jco_darray_read_dimension(zval *object, zval *zv_offset, int type TSRMLS_DC) {     jco_darray *intern = zend_object_store_get_object(object TSRMLS_CC);          if (intern-&gt;std.ce-&gt;parent) {         return zend_get_std_object_handlers()-&gt;read_dimension(object, zv_offset, type TSRMLS_CC);     }      if (!zv_offset) {         zend_throw_exception(NULL, &quot;Cannot append to a jco_darray&quot;, 0 TSRMLS_CC);         return NULL;     }      long offset = zval_to_long(zv_offset);     if (offset &lt; 0 || offset &gt; jco_ds_darray_length(intern-&gt;array)) {         zend_throw_exception(NULL, &quot;Offset out of range&quot;, 0 TSRMLS_CC);         return NULL;     }      zval *return_value;     zval *value = jco_ds_darray_get(intern-&gt;array, offset);      if (value) {          if (type != BP_VAR_R && type != BP_WAR_RW) {             return_value = value;             Z_SET_ISREF_P(return_value);         } else {             MAKE_STD_ZVAL(return_value);             ZVAL_ZVAL(return_value, value, 1, 0);             Z_DELREF_P(return_value);         }     } else {         MAKE_STD_ZVAL(return_value);         ZVAL_NULL(return_value);         Z_DELREF_P(return_value);     }      return return_value; }   static void jco_darray_write_dimension(zval *object, zval *zv_offset, zval *value TSRMLS_DC) {     jco_darray *intern = zend_object_store_get_object(object TSRMLS_CC);      if (intern-&gt;std.ce-&gt;parent) {         return zend_get_std_object_handlers()-&gt;write_dimension(object, zv_offset, value TSRMLS_CC);     }       if (!zv_offset) {         zend_throw_exception(NULL, &quot;Cannot append to a jco_darray&quot;, 0 TSRMLS_CC);     }      long offset = zval_to_long(zv_offset);     if (offset &lt; 0) {         zend_throw_exception(NULL, &quot;Offset out of range&quot;, 0 TSRMLS_CC);     }      zval *saved_val = jco_ds_darray_set(intern-&gt;array, (size_t)offset, value);     if (saved_val == NULL) {         zend_throw_exception(NULL, &quot;Error occured during dimension write&quot;, 0 TSRMLS_CC);     } }    static int jco_darray_has_dimension(zval *object, zval *zv_offset, int check_empty TSRMLS_DC) {     jco_darray *intern = zend_object_store_get_object(object TSRMLS_CC);      if (intern-&gt;std.ce-&gt;parent) {         return zend_get_std_object_handlers()-&gt;has_dimension(object, zv_offset, check_empty TSRMLS_CC);     }      long offset = zval_to_long(zv_offset);     if (offset &lt; 0 || offset &gt; jco_ds_darray_length(intern-&gt;array)) {         return 0;     }      zval *value = jco_ds_darray_get(intern-&gt;array, offset);     if (value == NULL) {         return 0;     }      if (check_empty) {         return zend_is_true(value);     } else {         return Z_TYPE_P(value) != IS_NULL;     }  }  static void jco_darray_unset_dimension(zval *object, zval *zv_offset TSRMLS_DC) {     jco_darray *intern = zend_object_store_get_object(object TSRMLS_CC);      if (intern-&gt;std.ce-&gt;parent) {         return zend_get_std_object_handlers()-&gt;unset_dimension(object, zv_offset TSRMLS_CC);     }      long offset = zval_to_long(zv_offset);     if (offset &lt; 0 || offset &gt; jco_ds_darray_length(intern-&gt;array)) {         zend_throw_exception(NULL, &quot;Offset out of range&quot;, 0 TSRMLS_CC);     }      jco_ds_darray_unset(intern-&gt;array, offset); }  int jco_darray_count_elements(zval *object, long *count TSRMLS_DC) {     jco_darray *intern = zend_object_store_get_object(object TSRMLS_CC);      if (intern-&gt;std.ce-&gt;parent) {         return zend_get_std_object_handlers()-&gt;count_elements(object, count TSRMLS_CC);     }      if (intern && intern-&gt;array) {         *count = (long)jco_ds_darray_count(intern-&gt;array);         return SUCCESS;     } else {         *count = 0;         return FAILURE;     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f jco_darray_read_dimension, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0440\u0435\u0442\u044c\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 type. \u042d\u0442\u043e \u0444\u043b\u0430\u0433, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0432 \u043a\u0430\u043a\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f BP_VAR_R, BP_VAR_W, BP_VAR_RW, BP_VAR_IS \u043b\u0438\u0431\u043e BP_VAR_UNSET.  <\/p>\n<pre><code class=\"php\">$var[0][1]; \/\/ \u043e\u0431\u0430 \u0441\u043b\u0443\u0447\u0430\u044f read_dimension BP_VAR_R $var[0][1] = 1; \/\/ [0] - read_dimension BP_VAR_W, \u0430 [1] - write_dimension  isset($var[0][1]); \/\/ [0] - read_dimension BP_VAR_IS, \u0430[1] - has_dimension <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c type \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u043e\u043f\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 BP_VAR_W \u043c\u044b \u043e\u0442\u0434\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0430 \u0447\u0442\u043e\u0431\u044b \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430 \u043d\u0435 \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0441\u0442\u0430\u0432\u0438\u043c zval-&gt;is_ref__gc = 1 (\u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u0445\u0430\u043a).<\/p>\n<p>  \u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 (intern-&gt;std.ce-&gt;parent). \u042d\u0442\u043e \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0448\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b ArrayAccess.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b php \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 jco_darray_init \u0441\u043b\u0443\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438  <\/p>\n<pre><code>    jco_darray_handlers.has_dimension   = jco_darray_has_dimension;     jco_darray_handlers.read_dimension  = jco_darray_read_dimension;     jco_darray_handlers.write_dimension = jco_darray_write_dimension;     jco_darray_handlers.unset_dimension = jco_darray_unset_dimension;     jco_darray_handlers.count_elements  = jco_darray_count_elements;     jco_darray_handlers.clone_obj = jco_darray_clone; <\/code><\/pre>\n<p>  C\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c php c \u043d\u0430\u0448\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c  <\/p>\n<pre><code class=\"bash\">    make && make install <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/php -dextension=jco.so jco.php  JCO\\Darray TIME: 0.18597507476807 MEMORY: 11.44548034668 Array TIME: 0.33455300331116 MEMORY: 137.51664733887 <\/code><\/pre>\n<p>  \u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043d\u0438\u0436\u0435, \u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u044b\u0448\u0435 \u043f\u043e\u0447\u0442\u0438 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430. \u0423\u0441\u043f\u0435\u0445!<\/p>\n<h3>Traversable<\/h3>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u044b\u043b \u0441\u043e\u0432\u0441\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c, \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u043c. \u0412 object_handlers \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043d\u0435\u0442, \u043d\u043e \u0432\u043e\u0442 \u0432 zend_class_entry \u0435\u0441\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044f get_iterator \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_iterators.h#_zend_class_iterator_funcs\">iterator_funcs<\/a>. <\/p>\n<p>  get_iterator \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <a href=\"http:\/\/lxr.php.net\/xref\/PHP_5_6\/Zend\/zend_iterators.h#_zend_object_iterator\">zend_object_iterator<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 foreach).  <\/p>\n<pre><code>struct _zend_object_iterator {     void *data; \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0434\u043e\u043f. \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430     zend_object_iterator_funcs *funcs; \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430     ulong index; \/\/\u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u043e\u043f\u043a\u043e\u0434\u043e\u0432. \u041c\u044b \u0435\u0433\u043e \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c }; <\/code><\/pre>\n<p>  iterator_funcs, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f \u043f\u043e\u043d\u044f\u043b, \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430: \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b Iterator \u0438\u043b\u0438 IteratorAggregate. \u041f\u043e\u043b\u044f zf_* \u2014 (\u043a\u044d\u0448\u0438?) \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 php \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0410 funcs \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043f\u043e\u043b\u044e \u0438\u0437 _zend_object_iterator. \u0411\u044b\u043b\u043e \u0431\u044b \u0445\u043e\u0440\u043e\u0448\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f iterator_funcs.<\/p>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 jco_darray.c \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b jco_darray \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0443\u0436\u043d\u044b\u0445 \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.   <\/p>\n<pre><code>typedef struct _jco_darray_iterator_data {     zval *object_zval; \/\/\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 php \u043e\u0431\u044a\u0435\u043a\u0442 (\u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u0442\u0435\u0440\u0438\u0440\u0432\u0430\u043d\u0438\u044f \u0435\u0433\u043e \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u043d\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0438\u043b\u0438)     jco_darray *object; \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 zend_object     size_t offset; \/\/ \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f     zval *current; \/\/ \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 } jco_darray_iterator_data;  <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e get_iterator. \u0412 jco_darray.c \u043f\u043e\u0441\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 count_elements \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e jco_darray_get_iterator.  <\/p>\n<pre><code>\/\/by_ref - \u0444\u043b\u0430\u0433, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435. zend_object_iterator *jco_darray_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) {     zend_object_iterator *iter;     jco_darray_iterator_data *iter_data;      if (by_ref) {         zend_throw_exception(NULL, &quot;UPS, no by reference iteration!&quot;, 0 TSRMLS_CC);         return NULL;     }      iter = emalloc(sizeof(zend_object_iterator));     iter-&gt;funcs = &jco_darray_iterator_funcs;      iter_data = emalloc(sizeof(jco_darray_iterator_data));     iter_data-&gt;object_zval = object;     Z_ADDREF_P(object);      iter_data-&gt;object = zend_object_store_get_object(object TSRMLS_CC);     iter_data-&gt;offset = 0;     iter_data-&gt;current = NULL;      iter-&gt;data = iter_data;      return iter; }  <\/code><\/pre>\n<p>  \u0418 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0445 \u043f\u0435\u0440\u0435\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 get_iterator.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">jco_darray.c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>static void jco_darray_iterator_dtor(zend_object_iterator *intern TSRMLS_DC) {     jco_darray_iterator_data *data = (jco_darray_iterator_data *)intern-&gt;data;      if (data-&gt;current != NULL) {         zval_ptr_dtor(&data-&gt;current);     }      zval_ptr_dtor((zval **)&data-&gt;object_zval);     efree(data);     efree(intern); }  static int jco_darray_iterator_valid(zend_object_iterator *intern TSRMLS_DC) {     jco_darray_iterator_data *data = (jco_darray_iterator_data *)intern-&gt;data;      return jco_ds_darray_length(data-&gt;object-&gt;array) &gt; data-&gt;offset ? SUCCESS : FAILURE; }  \/\/ static void jco_darray_iterator_get_current_data(zend_object_iterator *intern, zval ***data TSRMLS_DC) {     jco_darray_iterator_data *iter_data = (jco_darray_iterator_data *)intern-&gt;data;      if (iter_data-&gt;current != NULL) {         zval_ptr_dtor(&iter_data-&gt;current);         iter_data-&gt;current = NULL;     }      if (iter_data-&gt;offset &lt; jco_ds_darray_length(iter_data-&gt;object-&gt;array)) {         zval *value = jco_ds_darray_get(iter_data-&gt;object-&gt;array, iter_data-&gt;offset);         if (value != NULL) {             MAKE_STD_ZVAL(iter_data-&gt;current);             ZVAL_ZVAL(iter_data-&gt;current, value, 1, 0);              *data = &iter_data-&gt;current;         } else {             *data = NULL;         }      } else {         *data = NULL;     } }   #if ZEND_MODULE_API_NO &gt;= 20121212 \/\/ \u0432\u0435\u0440\u0441\u0438\u0438 php 5.5+ static void jco_darray_iterator_get_current_key(zend_object_iterator *intern, zval *key TSRMLS_DC) {     jco_darray_iterator_data *data = (jco_darray_iterator_data *) intern-&gt;data;     ZVAL_LONG(key, data-&gt;offset); } #else \/\/\u0412 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0438 \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \/\/ \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c HASH_KEY_IS_STRING, HASH_KEY_IS_LONG \u0438\u043b\u0438 HASH_KEY_NON_EXISTANT static int jco_darray_iterator_get_current_key(zend_object_iterator *intern, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) {     jco_darray_iterator_data *data = (jco_darray_iterator_data *) intern-&gt;data;      *int_key = (ulong) data-&gt;offset;     return HASH_KEY_IS_LONG; } #endif  static void jco_darray_iterator_move_forward(zend_object_iterator *intern TSRMLS_DC) {     jco_darray_iterator_data *data = (jco_darray_iterator_data *) intern-&gt;data;      data-&gt;offset++; }  static void jco_darray_iterator_rewind(zend_object_iterator *intern TSRMLS_DC) {     jco_darray_iterator_data *data = (jco_darray_iterator_data *) intern-&gt;data;      data-&gt;offset = 0;     data-&gt;current = NULL; }  static zend_object_iterator_funcs jco_darray_iterator_funcs = {     jco_darray_iterator_dtor,     jco_darray_iterator_valid,     jco_darray_iterator_get_current_data,     jco_darray_iterator_get_current_key,     jco_darray_iterator_move_forward,     jco_darray_iterator_rewind,     NULL }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 jco_darray_init \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0448 get_iterator.  <\/p>\n<pre><code>    jco_darray_ce-&gt;get_iterator = jco_darray_get_iterator;     jco_darray_ce-&gt;iterator_funcs.funcs = &jco_darray_iterator_funcs; <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 foreach  <\/p>\n<pre><code class=\"php\">foreach($jar as $val) {     if(($val % 100000) == 0) {         echo $val . PHP_EOL;     } } <\/code><\/pre>\n<p>  C\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c php c \u043d\u0430\u0448\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c  <\/p>\n<pre><code class=\"bash\">    make && make install <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">~\/dev\/bin\/php\/bin\/php -dextension=jco.so jco.php <\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0432\u0441\u0435. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 Traversable \u0438 ArrayAccess \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0445\u043e\u0434\u0443\u0435\u0442 \u043d\u0430 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 PHP. \u0417\u0430 \u0431\u043e\u0440\u0442\u043e\u043c \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043d\u043e \u0437\u0430 \u043d\u0435\u0439 \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0435\u0439 <a href=\"http:\/\/www.phpinternalsbook.com\/classes_objects\/serialization.html\">\u0433\u043b\u0430\u0432\u0435<\/a> php internals book.<\/p>\n<p>  \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u043d\u043e\u0432\u043e\u043c phpng \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e\u0435 (\u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e \u0441\u0438\u043b\u044c\u043d\u043e <a href=\"https:\/\/nikic.github.io\/2014\/12\/22\/PHPs-new-hashtable-implementation.html\">\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u044b<\/a>), \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c. <\/p>\n<p>  \u0418 \u0434\u0430, \u044f \u0441\u043e\u0432\u0440\u0430\u043b. \u0412\u043e\u0442 \u0432\u0430\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/cee\/55a\/9db\/cee55a9dbbc540a48d1e88a1887fb0e1.png\"\/>     \t<\/p>\n<div class=\"clear\"><\/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\/260983\/\"> http:\/\/habrahabr.ru\/post\/260983\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b Traversable \u0438 ArrayAccess.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043b\u0435\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0441\u044b\u043b\u043e\u043a.  <\/p>\n<ul>\n<li><a href=\"http:\/\/lxr.php.net\/\">lxr.php.net<\/a> \u2014 \u0423\u0434\u043e\u0431\u043d\u0435\u0439\u0448\u0438\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 php;<\/li>\n<li><a href=\"http:\/\/www.phpinternalsbook.com\/\">phpinternalsbook<\/a> \u2014 \u041f\u043e\u043b\u0435\u0437\u043d\u0435\u0439\u0448\u0438\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u043f\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c php. \u0410 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u043e <a href=\"http:\/\/www.phpinternalsbook.com\/classes_objects.html\">\u043a\u043b\u0430\u0441\u0441\u0430\u043c<\/a>;<\/li>\n<li><a href=\"https:\/\/php.net\/manual\/ru\/internals2.php\">\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u044f\u0434\u0440\u0443 PHP<\/a>.<\/li>\n<\/ul>\n<p>  \u0418 \u043f\u0440\u043e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443: \u044f \u043f\u0438\u0441\u0430\u043b \u043a\u043e\u0434 \u043f\u043e ubuntu, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 linux \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u043e\u0432 (\u0434\u0430 \u0438 OS X) \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 (\u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c apt-get). \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434 Windows, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445 (<s>\u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043f\u0438\u0448\u0435\u0442 \u043a\u043e\u0434 \u043f\u043e windows<\/s>).<\/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-259952","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/259952","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=259952"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/259952\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=259952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=259952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=259952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}