易截截图软件、单文件、免安装、纯绿色、仅160KB

php variable circular reference

 
Php Variable Circular References

Circular-references has been a long outstanding issue with PHP. They are
caused by the fact that PHP uses a reference counted memory allocation
mechanism for its internal variables. This causes problems for longer
running scripts (such as an Application Server
or
the eZ Components
test-suite) as the memory is not freed until the end of the request. But
not everybody is aware on what exactly the problem is, so here is a
small introduction to circular references in PHP.

In PHP a refcount value is kept for every variable container (zval).
Those containers are pointed to from a function's symbol table that
contains the names of all the variables in the function's scope. Every
variable, array element or object property that points to a zval will
increase its refcount by one. The refcount of a zval container is
decreased by one whenever call unset() on a variable name that points to
it, or when a variable goes away because the function in which it was
used ends. For a more thorough explanation about references, please see
the article on this
that I
wrote for php|architect
some time
ago.

The problems with circular references all start by creating an array or
an object:

<?php
$tree = array( 'one' );
?>
This creates the following structure in memory:


Now if we proceed to add a new element to the array, that points back to
the array with:

<?php
$tree[] = $tree;
?>
We create a circular reference like this:


As you can see there are two variable names pointing to the array
itself. Once through the $tree variable, and once through the 2nd
element of the array. Because there are two variable names pointing to
the container, its refcount is 2.

Now, the next step that actually creates the problem if we unset() the
$tree variable. As I mentioned before an unset() on a variable name will
decrease the refcount of the variable container the variable poi


相关文档:

PHP的CRUD类

因为项目需要,所以自己写了一个CRUD类
虽然还比较简单,不过感觉很实用。
注:cls_database是一个数据库操作类
见:http://code.google.com/p/cyy0523xc/source/browse/trunk/php/cls_crud.php
<?php
/**
* 自动化数据表操作类
* @author 小蔡 <cyy0523xc@gmail.com>
* @version 1.0
*/
class cls_ ......

linux下安装PHP APACHE MYSQL 手记

/**********************************
APACHE
***********************************/
编辑参数:
./configure" \
"--prefix=/usr/local/apache" \
"--enable-so" \
"--enable-ssl" \
"--enable-mods-shared=most" \
"--with-mpm=event" \
"--with-ssl=/usr/local/openssl" \
"--enable-cache" \
"--enable-mem- ......

PHP单双引号的问题

基础问题:
最近被单双引号困扰着,不知道什么时候用双引号,什么时候用单引号。总结区分一下
在大部份语言中,引号引起来的内容都表示为字符。
例如:
      <a href="地址">链接</a>
      echo "字符串";
      print("字 ......

JSON在PHP中的应用


  互联网的今天,AJAX已经不是什么陌生的词汇了。说起AJAX,可能会立即想起因RSS而兴起的XML。XML的解析,恐怕已经不是什么难题了,特别是PHP5,大量的XML解析器的涌现,如最轻量级的SimpleXML。不过对于AJAX来说,XML的解析更倾向于前台Javascript的支持度。我想所有解析过XML的人,都会因树和节点而头大。不可否认,X ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号