2008年7月22日 星期二

memory_get_usage

$begin = memory_get_usage();
$foo = &new Foo();
$second = memory_get_usage();
echo "allocation time: ".( $second-$begin) . "
";

2008年7月21日 星期一

CLI run CI

from

http://codeigniter.com/forums/viewthread/78610/


Thanks for your help but i did a file who modify routes.php with sed (unix-command) because the OS is FreeBSD and then this file execute the index.php with the good route.
exec("sed -i.bak 's/\".*\";/\"controllers_name\";/1' ./system/application/config/routes.php",$sortie);
$argv=$_SERVER['argv'];
$argc=$_SERVER['argc'];
$str='';
for($i=1;$i<$argc;$i++)
$str=$str.' '.$argv[$i];
passthru("php index.php".$str,$s);
exit($s);

2008年7月8日 星期二

Variable scope

http://tw2.php.net/global

Using static variables

Another important feature of variable scoping is the static variable. A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope. Consider the following example:

function Test()
{
$a = 0;
echo $a;
$a++;
}
?>


Static variables also provide one way to deal with recursive functions. A recursive function is one which calls itself. Care must be taken when writing a recursive function because it is possible to make it recurse indefinitely. You must make sure you have an adequate way of terminating the recursion. The following simple function recursively counts to 10, using the static variable $count to know when to stop:


function Test()
{
static $count = 0;

$count++;
echo $count;
if ($count < 10) {
Test();
}
$count--;
}
?>
-------------------------------------------------------------------------
class Foo
{
public static $my_static = 'foo';

public function staticValue() {
return self::$my_static;
}
}

class Bar extends Foo
{
public function fooStatic() {
return parent::$my_static;
}
}


print Foo::$my_static . "\n";

$foo = new Foo();
print $foo->staticValue() . "\n";
print $foo->my_static . "\n"; // Undefined "Property" my_static

print $foo::$my_static . "\n";
$classname = 'Foo';
print $classname::$my_static . "\n"; // As of PHP 5.3.0

print Bar::$my_static . "\n";
$bar = new Bar();
print $bar->fooStatic() . "\n";

關於我自己

Aspire freedom , Hope to do Soming make self complete ~