PHP Backend Application(1)Env and PHP Knowledge

PHP Backend Application(1)Env and PHP Knowledge

Check the PHP version
> php --version
PHP 5.6.16 (cli) (built: Dec 26 2015 18:37:18)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

The comments style is similar to Java, file starter and end are like this
<?php
  echo "php runs first!";
  echo "\nrecall my php knowledge"; // one line comments
  /*
   this is how th comments go in java
  */
?>

Types
Four scalar type: boolean, integer, float, string
Two compound types: array, object
Two special types: resource, NULL

Check the type and get type
<?php
$a_boolean = TRUE;
$a_string = "foo";

echo gettype($a_boolean);
echo "\n";
echo var_dump($a_string);
echo is_string($a_string);
echo "\n";

?>

console output is as follow:
boolean
string(3) "foo"
1

Cast other value to boolean
var_dump((bool) 1);         // bool(true)
var_dump((bool) -2);        // bool(true)

Automatically covert the int to float
$large_number = 2147483647;

var_dump($large_number);                     // int(2147483647)

$large_number = 2147483648;
var_dump($large_number);                     // float(2147483648)

Single Quoted for String
// Outputs: This will not expand: \n a newline

echo 'This will not expand: \n a newline';

// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';

Double Quoted

Heredoc
$str = <<<EOD

Example of string
spanning multiple lines
using heredoc syntax.
EOD;

nowdoc is single quoted heredoc
echo <<<'EOT'

My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should not print a capital 'A': \x41
EOT;

Environment and Types
> cat type.php
<?php
$arr = array("foo"=>1, 12=>true);
echo gettype($arr[12])."\n";
echo $arr[12]."\n";
?>

> php type.php
boolean
1

unset($arr[5]); // This removes the element from the array
unset($arr);    // This deletes the whole array

As mentioned above, if no key is specified, the maximum of the existing integer indices is taken, and the new key will be that maximum value plus 1.

A lot of useful array operations are here http://sillycat.iteye.com/blog/1543227

The unset() function allows removing keys from an array. Be aware that the array will not be reindexed.

The array_values() function can be used to 'remove and shift'.
$a = array(1 => 'one', 2 => 'two', 3 => 'three');
unset($a[2]);
/* will produce an array that would have been defined as
   $a = array(1 => 'one', 3 => 'three');
   and NOT
   $a = array(1 => 'one', 2 =>'three');
*/
print_r($a);
echo "<br />";
$b = array_values($a);
// Now $b is array(0 => 'one', 1 =>'three')
print_r($b);

http://sillycat.iteye.com/blog/2302285

Code Standard
http://sillycat.iteye.com/blog/2194084

PHP with FPM
http://sillycat.iteye.com/blog/2223621

PHP Lumen
http://sillycat.iteye.com/blog/2238841
http://sillycat.iteye.com/blog/2239826

Install latest PHP on EC2
http://sillycat.iteye.com/blog/2302287

UNIT Test
http://sillycat.iteye.com/blog/2302288

> phpunit --version
PHPUnit 5.1.3 by Sebastian Bergmann and contributors.

References:
PHP Basic1 ~ 3
http://sillycat.iteye.com/blog/768664
http://sillycat.iteye.com/blog/769110
http://sillycat.iteye.com/blog/770369

PHP 1~ 8
http://sillycat.iteye.com/blog/1543227
http://sillycat.iteye.com/blog/2066063
http://sillycat.iteye.com/blog/2302285
http://sillycat.iteye.com/blog/2194084
http://sillycat.iteye.com/blog/2223621
http://sillycat.iteye.com/blog/2238841
http://sillycat.iteye.com/blog/2239826

Language References
http://php.net/manual/en/langref.php

PHP Env
http://sillycat.iteye.com/blog/1634562
http://sillycat.iteye.com/blog/1638638

猜你喜欢

转载自sillycat.iteye.com/blog/2302808
php