易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

Run PHP on the Google App Engine

Google launched their Google App Engine (GAE) a year ago. The free hosting in App Engine is allocated 500 MB of persistent storage and enough CPU and bandwidth for about 5 million page views a month. Also, if you really want more you can see pricing plans.
GAE will support Java going forw ......

php int型的最大值

执行以下语句:
var_dump(2147483647); // int
var_dump(
2147483648); // float
可以看到,php int型的最大值就是
2147483647,即231
-1,因为32位的最高位要用来表示正负。
再执行以下语句:
$u = sprintf("%u",
2147483648); # 更换为%b,%d试试
var_dump($u);
......

关于php面向对象的静态变量的问题


代码如下:
<?php
class Book{
    static $num=0;
    public function showme(){
        echo '您是第'.self::$num.'位访客';
        self::$num++;
     ......

PHP初学者常见问题总结


本文列出了所有初学者最常见的PHP问题
【1】页面之间无法传递变量 get,post,session在最新的php版本中自动全局变量是关闭的,所以要从上一页面取得提交过来得变量要使用$_GET['foo'],$_POST['foo'],$_SESSION['foo']来得到
当然也可以修改自动全局变量为开(php.ini改为register_globals = On);考虑到兼容性,还是强迫 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号