PHP 7 hi project-ah chuan ka la hmang miah lo va, mah se xampp-win32-7.0.4-0-VC14-installer tang hian eng eng emaw chu ka han bih ve kual a. Wamp lam hi chuan PHP 7 hi an la pack ve rih lo. Chu bakah Internet leh stackoverflow vel a, mi te thlir dan te pawh ka enkual bawk a. Saptawng hlirin an lo ziak bawk si a, chuvangin hriatthiam loh ka ngah nasa ta mai. Chuvangin kei ang bawka blind tan Duhlian tawng ngatin tangkai deuh nia ka hriatte ka rawn dahkhawm e.
PHP 7-a thil thar te chu i lo bih dawn teh ang:
PHP 7-a thil thar te chu i lo bih dawn teh ang:
- Scalar Type Hints: Language dangah chuan type hi an hmang thup a, PHP pawh hian Version 5 tangin a hmang tan a, mahse Classes, Array leh Callable-ah chauh hman theih a ni a. PHP 7 ah chuan Scalar type hint an tih mai integers, floating point numbers, booleans and strings te hi hman theih an lo ni ta:
Example: int($a); string($a);
Kan hriat ve mai mai atan: Type hrang hrang kan hman theih te chu: class/interface name, self, array, callable, bool, float, int leh string te an ni ta. - Return Type Declaration: data fir leh a nihna ang taka lakluh or dahluh (input consistency) nan type hint kan hman laiin data dik tak dahchhuah(output consistency) nan return type hi kan hmang ve thung a.
Example:function add(int $a, int $b): int{ return (string)($a + $b); }
Entirnaah hian kan return duh chu : int{ } hmangin kan kualkhung a ni. return hmaa :(colon) hi a pawimawh hle a, theihnghilh palh a awl bawk. - Anonymous Classes: Class chungchang hi chu sawikual vak tur pawh ka hre bik lo, mite sawi ang ang hi e,ee..ti liam ve mai chi ka ni a. Class hming nei lo a nihna chiah hi class pangai nen an in anlohna chu ni ta maiin ka hria.
Example:
kan hmuh ang hian PHP 7 tang chuan new hmang hian class hming nei lo kan siam zung zung thei tihna a ni. He thil hi a la tangkai viauvin a rinawm. A chhan chu Class hming nei kan siam a, chuta tang chuan class dang siamin a property leh method te kan chhawm (inherit) thei a, mahse class (hmingnei) dang siam buai ngai lovin anonymous hi kan hmang zung zung thei dawn a ni.$object = new class( 'arguments' ) { // defined properties and methods};
- Closure::call() method: Closure hi function hming nei lo sawina tawngkam dang a ni a, Class leh function dangah te bel theih a ni a. PHP5 chinah chuan Class method tan closure hi kan hmang thei tawh a. Entirna nen en ila a chiang zawk ang:
//Class Foo kan siam a
Kan hmuh ang hian PHP 7-ah chuan call hmangin tawi leh samkhai takin kan tithei tawh a ni.
class Foo {
private $foo = 'bar';
}
//Function hming nei lo siam leh ila
$getFooCallback = function() {
return $this->foo;
};
//PHP5 style
$binding = $getFooCallback->bindTo(new Foo,'Foo');
echo $binding().PHP_EOL;
//PHP7 style
echo $getFooCallback->call(new Foo).PHP_EOL; - Generator Delegation: PHP 5.5 tang khan generator hi a awm tan a, mahse generator hi a tangkai ang tak hian developer tam zawkin an chhawr lem lo. Generator tangkaina ber chu memory-a array siam ngai lo va foreach loop-a array siamna a ni. Entirna nen lo hi chuan sawifiah thiam a har a:
Example:function getSailo($mizos){
A chunga mi hi Generator version-ah lo dah dawn ta ila:
$filteredSailo = [];
foreach ($mizos as $sailo) {
$filteredSailo[] = $mizo;
}
return $filteredSailo;
}function getSailo($mizos){
Wow...a tawiin a awlsam phian mai...getSailo function hnathawh chu Sailo zawng zawng lakkhawm a ni a, Hauhnar lakchhuahna lo siam dawn ta ila. getHauhnar($mizos); kan lo nei ang. Tichuan getHauhnar() leh getSailo function-a kan data neih te chu lo finkhawmin getMizo() lo siam dawn ta ila, PHP 7 tel lo chuan har talh tawh ang. PHP 7 chuan Generator Delegation a neih a vangin a hnuaia mi ang getMizo function chu kan nei thei ang:
foreach ($mizos as $sailo) {
yield $sailo;
}
}function getMizo($mizos){
Tichuan hetiang hian ka lachhuak thei ang:
yield from getSailo($mizos);
yield from getHauhnar($mizos);
}foreach(getMizo($mizos) as $mizo):
Hei hi nia Generator Delegation an tih chu.......
echo $mizo, PHP_EOL;
endforeach; - Generator return expression: Generator return values return nan getReturn method hi PHP 7-ah dah tel a ni bawk.
Example:$gen = (function() {
yield 1; yield 2; return 3;
})();
foreach ($gen as $val) {
echo $val, PHP_EOL;
}
echo $gen->getReturn(), PHP_EOL; - Null Coalesce Operator: isset hman tluk tluk aiah a aia tawi ?? hman theih a ni ta:
//PHP 5 Version-ah chuan
//PHP 7 Version$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
In tawi hleih bakah hman a in nawm hleih tawh dawn hlein a lang.$username = $_GET['user'] ?? 'nobody';
- Spaceship Operator: Thil pahnih khaikhinna tangin te zawk, intluk, lianzawk chawhchhuahna <=> thar a rawn piang bawk a. a hnathawh tang hian a hman dan turah chuan kan chiang thei ber ang:
echo 1 < = > 1; // 0
echo 1 < = > 2; // -1
echo 2 < = > 1; // 1 - Throwable: PHP 7-a change lian tak mai chu PHP-in error a handle dan hi a ni. Error te hi exception anga dah an ni vek tawh a ni. Chuvangin Try/Catch block hmangin error leh exception chu Throwable(paihtheih)ah kan siam thei tihna a ni. Hetihrual hian error chu object object error anga laktheih a ni bawk. Error kan catch theih te chu:
- Dirname: dirname function hi parent directory path enna a ni a, mahse Directory hrang hrang leh sub directory vela luhkual thui hi chuan inchhui ngial a ngai tawh thin a. He buaina ching fel tur hian PHP 7-ah chuan second argument Levels an rawn dah tel a, level hi integer 1 aia tlem lo hman tur a ni.
echo dirname('/usr/local/bin',2).PHP_EOL;
- Integer Division: Eng ang tak nasaa tangkai nge a nih leh a pawimawhna em em chu ka hriat phak ni lo mah se intdiv() function hi PHP 7-ah hian an rawn dah teh tlat mai a. Entirnan 10/5 tih aiah intdiv(10,5); a tih theih tihna anih chu.
- Array Constant: PHP 5-ah chuan array constant definition siam nan const kan hmang a, PHP 7-ah chuan define hmangin tih theih a ni tawh bawk:
Example:
//PHP 5 Version
//PHP 7 Versionconst ANIMALS = array('dog', 'cat', 'bird');
echo ANIMALS[1]; // outputs "cat"define('ANIMALS', array(
'dog',
'cat',
'bird'
));
echo ANIMALS[1]; // outputs "cat" - Session Options: PHP 7-ah chuan session_start hian array option a support ta e. hei hian Session configuration directive php.ini file-a mi pawh a override vek thei bawk.
session_start([
'cache_limiter' => 'private',
'read_and_close' => true,
]); - Performance: PHP 7 hi PHP 5.6 let hnih vela chak tura ngaih a ni a, then khat chuan HHMV (HIP HOP Virtual Machine-Hack PHP) ai pawhin a chak zawk niin an sawi bawk a. stable version an release tawh bawk a.
No comments :
Post a Comment