2014/12/19

php study memo

Each active resource has a unique identifier. Each identifier is a numerical index into
an internal PHP lookup table that holds information about all the active resources. PHP
maintains information about each resource in this table, including the number of references
to (or uses of) the resource throughout the code. When the last reference to a
resource value goes away, the extension that created the resource is called to free any
memory, close any connection

=->
$res=database_connect();
...
$res="boo"

automatic cleanup

// is_resource()
==>Many modules provide several functions for dealing with the outside world

if(is_resource($..)){
   
}

is_null($x)


★static variables
function updateCounter(){
     static  $counter=0;
     $counter ++;
     echo "Static function variables is now {$counter}\n";
}



★copy on write----------
必要な時だけ、メモリーを使う

Symbol
Each value pointed to by a symbol table has a reference count, a number that represents
the number of ways there are to get to that piece of memory. After the initial assignment
of the array to $worker and $worker to $other, the array pointed to by the symbol table
entries for $worker and $other has a reference count of 2.1 In other words, that memory
can be reached two ways: through $worker or $other. But after $worker[1] is changed,
PHP creates a new array for $worker, and the reference count of each of the arrays is
only 1.


★function parameter----------------------
func_num_args ==>$#?
func_get_args=>
func_get_arg(1)=>$1

isset(a)
isset(b)
==>設定されている?


Single-quoted strings do not interpolate variables.
echo '$name'
==>$name


$a= array(,,)
print_r($a)

Beware of using print_r() or var_dump() on a recursive structure such as $GLOBALS
(which has an entry for GLOBALS that points back to itself). The print_r() function loops
infinitely, while var_dump() cuts off after visiting the same element three times.

var_dump(true)
==>bool(true)


★echo $_COOKIE['PHPSESSID'];
==>これはないと、何もかわらない。。
session_start() ;

Build-in PHP Data Objects
==>PDO
The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for
accessing databases in PHP. Each database driver that implements the PDO interface can
expose database-specific features as regular extension functions. Note that you cannot
perform any database functions using the PDO extension by itself; you must use a database-
specific PDO driver to access a database server.


file_exists($folder)
mkdir
folder
fread
fclose


imagecreate(width,heigth)
imagecolorallocate(image,red,green,blue)
imagegif
imagejpeg