Monday, 21 March 2016

PHP 7.0.4 i bih chiang ang aw........

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:
  1. 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.
  2. 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.
  3. 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:
    $object = new class( 'arguments' ) { // defined properties and methods};
    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.
  4. 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
    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;
    Kan hmuh ang hian PHP 7-ah chuan call hmangin tawi leh samkhai takin kan tithei tawh a ni.
  5. 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){
          $filteredSailo = [];  
         foreach ($mizos as $sailo) {
              $filteredSailo[] = $mizo;
         }
              return $filteredSailo;
     }
    A chunga mi hi Generator version-ah lo dah dawn ta ila:
    function getSailo($mizos){
      foreach ($mizos as $sailo) {
        yield $sailo;
      }
    }
    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:
    function getMizo($mizos){  
      yield from getSailo($mizos);  
      yield from getHauhnar($mizos);
    }
    Tichuan hetiang hian ka lachhuak thei ang:
    foreach(getMizo($mizos) as $mizo):
    echo $mizo, PHP_EOL;
    endforeach;
    Hei hi nia Generator Delegation an tih chu.......
  6. 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;
  7. Null Coalesce Operator: isset hman tluk tluk aiah a aia tawi ?? hman theih a ni ta:
    //PHP 5 Version-ah chuan
    $username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
    //PHP 7 Version
    $username = $_GET['user'] ?? 'nobody';
    In tawi hleih bakah hman a in nawm hleih tawh dawn hlein a lang.
  8. 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
  9. 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:
  10. 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;
  11. 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.
  12. 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
    const ANIMALS = array('dog', 'cat', 'bird');
    echo ANIMALS[1]; // outputs "cat"
    //PHP 7 Version
    define('ANIMALS', array(
        'dog',
        'cat',
        'bird'
    ));
    echo ANIMALS[1]; // outputs "cat"
  13. 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,
    ]);
  14. 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.
Heng bakah pawh hian security leh bug fix neuh neuh a tam hle turah ngai ila. Project thar-ah chuan hman chhin ve hrim hrim te pawh a thain a rinawm. He thuziak hi Internet information atanga remkhawm mai a ni e, chuvangin ngaihdan te sawi hreh lo ila, kan group hi i ti hlu zual teh ang u.