锟斤拷之前锟斤拷 PHP 锟芥本锟叫o拷 锟斤拷锟斤拷使锟矫撅拷态值锟斤拷锟斤拷锟藉常锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆硷拷指锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷默锟斤拷值锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷锟绞癸拷冒锟斤拷锟斤拷锟街碉拷锟斤拷址锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷约锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷诘锟斤拷锟街碉拷锟斤拷式锟斤拷 锟斤拷锟藉常锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆硷拷锟斤拷锟矫猴拷锟斤拷锟斤拷锟斤拷默锟斤拷值锟斤拷
<?php
const ONE = 1;
const TWO = ONE * 2;
class C {
const THREE = TWO + 1;
const ONE_THIRD = ONE / self::THREE;
const SENTENCE = 'The value of THREE is '.self::THREE;
public function f($a = ONE + self::THREE) {
return $a;
}
}
echo (new C)->f()."\n";
echo C::SENTENCE;
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
4 The value of THREE is 3
锟斤拷锟节匡拷锟斤拷通锟斤拷 const 锟截硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为 array 锟侥筹拷锟斤拷锟斤拷
<?php
const ARR = ['a', 'b'];
echo ARR[0];
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
a
锟斤拷锟节匡拷锟皆诧拷锟斤拷锟斤拷 func_get_args()锟斤拷 使锟斤拷 ... 锟斤拷锟斤拷锟� 锟斤拷实锟斤拷 锟戒长锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
<?php
function f($req, $opt = null, ...$params) {
// $params 锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷剩锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
printf('$req: %d; $opt: %d; number of params: %d'."\n",
$req, $opt, count($params));
}
f(1);
f(1, 2);
f(1, 2, 3);
f(1, 2, 3, 4);
f(1, 2, 3, 4, 5);
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
$req: 1; $opt: 0; number of params: 0 $req: 1; $opt: 2; number of params: 0 $req: 1; $opt: 2; number of params: 1 $req: 1; $opt: 2; number of params: 2 $req: 1; $opt: 2; number of params: 3
锟节碉拷锟矫猴拷锟斤拷锟斤拷时锟斤拷使锟斤拷 ... 锟斤拷锟斤拷锟斤拷锟� 锟斤拷 锟斤拷锟斤拷 锟斤拷 锟缴憋拷锟斤拷 锟斤拷锟斤拷展锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷裕锟斤拷锟斤拷锟� Ruby锟叫o拷锟解被锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
<?php
function add($a, $b, $c) {
return $a + $b + $c;
}
$operators = [2, 3];
echo add(1, ...$operators);
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
6
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� ** 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟姐。 同时锟斤拷支锟街硷拷写锟斤拷 **= 锟斤拷锟斤拷锟斤拷锟斤拷锟绞撅拷锟斤拷锟斤拷锟斤拷锟斤拷悴拷锟街碉拷锟�
<?php
printf("2 ** 3 == %d\n", 2 ** 3);
printf("2 ** 3 ** 2 == %d\n", 2 ** 3 ** 2);
$a = 2;
$a **= 3;
printf("a == %d\n", $a);
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
2 ** 3 == 8 2 ** 3 ** 2 == 512 a == 8
use 锟斤拷锟斤拷锟� 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷展锟斤拷支锟斤拷锟斤拷锟斤拷锟叫碉拷锟斤拷锟解部锟侥猴拷锟斤拷锟酵筹拷锟斤拷锟斤拷 锟斤拷应锟侥结构为 use function 锟斤拷 use const锟斤拷
<?php
namespace Name\Space {
const FOO = 42;
function f() { echo __FUNCTION__."\n"; }
}
namespace {
use const Name\Space\FOO;
use function Name\Space\f;
echo FOO."\n";
f();
}
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
42 Name\Space\f
PHP 锟斤拷 SAPI 模锟斤拷锟斤拷实锟斤拷锟斤拷一锟斤拷 锟斤拷锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 phpdbg锟斤拷锟斤拷锟斤拷锟斤拷息锟斤拷锟斤拷锟斤拷锟� » phpdbg 锟侥碉拷锟斤拷
锟斤拷锟斤拷一些锟街凤拷锟斤拷锟斤拷锟斤拷氐暮锟斤拷锟斤拷锟斤拷锟斤拷锟� htmlentities()锟斤拷 html_entity_decode() 锟皆硷拷 htmlspecialchars() 使锟斤拷 default_charset 锟斤拷为默锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷注锟解,锟斤拷锟斤拷 iconv锟斤拷锟斤拷锟窖凤拷锟斤拷锟斤拷 锟斤拷 mbstring 锟斤拷氐暮锟斤拷锟斤拷锟� 锟斤拷锟斤拷直锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷堑谋锟斤拷耄� 锟斤拷么锟斤拷些锟斤拷应锟斤拷锟矫碉拷锟斤拷锟饺硷拷锟斤拷锟斤拷 default_charset锟斤拷
default_charset 锟斤拷默锟斤拷值锟斤拷 UTF-8锟斤拷
只要锟斤拷锟斤拷要锟斤拷锟斤拷锟斤拷远锟轿打开诧拷锟斤拷取 php://input锟斤拷 同时锟斤拷锟斤拷锟斤拷锟斤拷锟绞癸拷锟斤拷诖锟斤拷锟� POST 锟斤拷锟斤拷锟捷碉拷时锟斤拷 锟斤拷锟斤拷锟斤拷锟皆斤拷锟酵讹拷锟斤拷锟节达拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
锟斤拷锟节匡拷锟斤拷支锟街达拷锟斤拷 2GB 锟斤拷锟侥硷拷锟较达拷锟斤拷
GMP 支锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷兀锟� 锟斤拷锟斤拷锟斤拷锟酵筹拷锟斤拷值锟斤拷锟酵★拷 锟斤拷使锟斤拷使锟斤拷 GMP 锟侥达拷锟斤拷锟斤拷锟街憋拷邸锟�
<?php
$a = gmp_init(42);
$b = gmp_init(17);
if (version_compare(PHP_VERSION, '5.6', '<')) {
echo gmp_intval(gmp_add($a, $b)), PHP_EOL;
echo gmp_intval(gmp_add($a, 17)), PHP_EOL;
echo gmp_intval(gmp_add(42, $b)), PHP_EOL;
} else {
echo $a + $b, PHP_EOL;
echo $a + 17, PHP_EOL;
echo 42 + $b, PHP_EOL;
}
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
59 59 59
锟斤拷锟斤拷 hash_equals() 锟斤拷锟斤拷锟斤拷 锟皆恒定锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟饺较o拷 锟皆憋拷锟斤拷时锟津攻伙拷锟斤拷 锟斤拷锟界当锟饺斤拷 crypt() 锟斤拷锟斤拷散锟斤拷值锟斤拷时锟津,就匡拷锟斤拷使锟矫此猴拷锟斤拷锟斤拷 锟斤拷锟劫讹拷锟姐不锟斤拷使锟斤拷 password_hash() 锟斤拷 password_verify()锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷也锟斤拷锟皆抵匡拷时锟津攻伙拷锟斤拷
<?php
$expected = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$correct = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$incorrect = crypt('1234', '$2a$07$usesomesillystringforsalt$');
var_dump(hash_equals($expected, $correct));
var_dump(hash_equals($expected, $incorrect));
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
bool(true) bool(false)
锟斤拷锟斤拷 __debugInfo()锟斤拷 锟斤拷使锟斤拷 var_dump() 锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷院锟街碉拷锟�
<?php
class C {
private $prop;
public function __construct($val) {
$this->prop = $val;
}
public function __debugInfo() {
return [
'propSquared' => $this->prop ** 2,
];
}
}
var_dump(new C(42));
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
object(C)#1 (1) { ["propSquared"]=> int(1764) }
锟斤拷锟斤拷 gost-crypto 散锟斤拷锟姐法锟斤拷 锟斤拷使锟斤拷 » RFC 4357, 11.2 小锟斤拷 锟斤拷锟斤拷锟� CryptoPro S-box 锟斤拷实锟斤拷锟斤拷 GOST 散锟叫猴拷锟斤拷锟斤拷
锟斤拷 PHP 5.6 锟叫讹拷 SSL/TLS 锟斤拷支锟街斤拷锟斤拷锟剿达拷锟斤拷鹊锟斤拷锟斤拷锟斤拷锟� 锟斤拷锟斤拷锟叫帮拷锟斤拷 默锟斤拷锟斤拷锟矫端碉拷锟斤拷证 选锟斤拷锟斤拷支锟斤拷证锟斤拷指锟狡比对o拷 锟皆憋拷锟斤拷 TLS 锟斤拷锟斤拷协锟教癸拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟剿很讹拷 SSL 锟斤拷锟斤拷锟斤拷选锟斤拷锟斤拷 锟皆憋拷锟斤拷使锟矫硷拷锟斤拷锟斤拷锟斤拷时锟斤拷 锟杰癸拷锟斤拷锟矫的匡拷锟斤拷协锟斤拷锟斤拷锟街わ拷锟斤拷锟斤拷锟斤拷锟矫★拷
锟斤拷些锟戒动锟斤拷 PHP 5.6.x 锟叫碉拷 OpenSSL 锟斤拷锟� 锟斤拷锟斤拷锟斤拷细锟斤拷锟斤拷锟斤拷
pgsql 锟斤拷展锟斤拷锟斤拷支锟斤拷
锟届步锟斤拷式锟斤拷锟斤拷锟斤拷锟捷库及执锟叫诧拷询锟斤拷
也锟斤拷锟斤拷锟斤拷使锟矫凤拷锟斤拷锟斤拷锟侥凤拷式锟斤拷 PostgreSQL 锟斤拷锟捷匡拷锟斤拷薪锟斤拷锟斤拷锟�
使锟斤拷 PGSQL_CONNECT_ASYNC
锟斤拷锟斤拷锟斤拷锟斤拷
锟斤拷锟斤拷锟届步锟斤拷锟接o拷pg_connect_poll()锟斤拷
pg_socket()锟斤拷
pg_consume_input() 锟斤拷 pg_flush() 锟斤拷锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟届步锟斤拷锟接和诧拷询锟斤拷