Wednesday, 23 March 2016

PHP Ruhrel Thar

PHP-7-ah thil thar kan hmu nual a, PHP hmelhriat tawh, hmelhriat tan leh la hmelhriat lutuk lo, a language zir rilruk ve deuh te tan PHP ruhrel thar (Internal Structure) PHP 7-a tunhnai maia an release chungchang hi sawilan ve thain ka hria a. Hetiang lam hre zawk te kut kuangkuaha thu mai mai te khan lo sit mai lovin lo belchiang ve ngei ula ka duh bawk a ni.

A hmasa ber chuan eng Software pawh a version thar an siam apiang hian a hma aia chak zawk tura code optimization hi a developer/programmer te'n an ngaihpawimawh ber te zinga mi a ni a. Hei hi Code refactoring ti tein an sawi thin bawk. PHP hmuchhuaktu, Rasmus Lerdorf chuan PHP 7 hi application hrang hranga 100% performance nei thei tur leh memory pawh heh lo ber tura duan a ni, tiin a sawi a. Hei bakah hian PHP khawlpui ber Zend Engine pawh thlak hlawkin hmingthar PHPNG (PHP Next Generation) tih an vuah sak a. Wordpress 4.1.1-a PHP version hrang hrang performance hi lo en ta ila, heta tang ringawt pawh hian PHP7 that zia chu hmuh hmaih chi a ni lo vang.


Performance-ah nasa takin hmasawnna kan hmuh bakah hian PHP7 hian Abstract Syntax tree (coding chepai kai) a rawn support tawh bawk a. Chuvangin Addons tool siam a awlsam tawh dawn bakah Static Analysis/profiling tan tangkai hle tura ngaih a ni bawk. Code kalphung danglam nasa tia sawi tur a awm lo va, Version hma lama yield hman apianga parenthesis ngai thin kha paih bo a ni tawh a, chutihrualin list() function argument nei lova hman thin erawh argument nei zela hman a ngai tawh thung dawn a. __clone magic method (hmanna ka neih awm pawh ka la hre lo) chu direct-a call theih a ni tawh bawk a. Thil dang an thlak danglam leh chu Uniform variable systax hi a ni a. Hei hian thil thlir dan thar leh zau zawk min siamsak bakah javascript code kalphung ang deuhva invoking function hman min phalsak a. Variable variable kalphung pawh thlak danglam a ni bawk. Thil thar dang leh chu 64-bit integer a rawn support hi a ni.

PHP7-ah hian PHP feature thenkhat paih leh thlak bakah dahbelh te an nei ve nual a. Version hma lama kan code hman kha depracated code a nih loh chuan la tha zel tura ngaih a ni. Code thenkhat dik thei lo erawh a awm ve zeuh thei bawk ang. PHP-a kan code dik loh vanga fatal error kan hmuh thin kha catchable-ah an dah vek thung a. Kan code ngai reng hmang si-a PHP 7-a insuan luh (upgrade) kan duh chuan hriat ngai leh thlak ngai tlema zawng a awm ve a. PHP-in complex variable variables a hriatthiam dan hi an thlak hlawk a, chuvangin variable variables i hmanna code chu uluk takin enfiah(test) phawt a fuh ber ang. assert() function hi configuration file atanga on leh off theihin an dah tawh bawk a. JSON extension an hman thin kha a free a nih loh vangin a free version-a thlak a ni tawh bawk a. Internal classes-ah error checking nan null i hman chuan exception anga an dah tawh avangin i code i revise ngei a ngai ang. is_numeric() function-ah hexadecimal number i pass chuan false a ni zel tawh ang. Hexadecimal leh a tlukpui decimal pawh i khaikhin chuan false a ni tawh bawk ang. Version hmasa lamah kha chuan tuna false kan tih te hi true an ni. Hexadecimal string leh Arithmetic Operator hman pawlh a rem tawh lo bawk a. Hexadecimal number te decimal number-a i convert duh chuan hexdec function hman tur a ni. Number pawh hexadecimal-a i convert duh chuan dechex function hman leh mai tur a ni. I code a uptodate chuan harsatna em em awm lovin PHP7-a i insuan zung zung thei ang. Version hma lama depracated code an tih ang chi kha PHP7-ah chuan an paih vek tawh avangin a hman theih loh a ni.

Version hmalama tangkai taka kan lo hman leh bel tawh PHP 7-a an paih te lo en thuak thuak leh ila. A hmasa ber chuan PHP 4 tanga kan hman mysql extension an paih hi a ni ang. Mak ve mai mai chu mysql ext hi kum 2015 hnu lam thleng pawha la hmang ngar ngar an la tam hle a. PHP 5.5 atang tawh khan injection attack laka a him loh em avangin hman tawh loh tura (deprecated) tih a ni a, mahse PHP zir tan tam zawk hi chuan an la hmang lui tho mai. PHP7-ah chuan mysqli or PDO chauh hman tur a ni ang. Mahse PHP7-ah hian mysql ext hi i la hmang duh cheu a nih chuan PECL(PHP Extension Community Library) atanga mysql extension hi install theih a la ni cheu tho. POSIX REGEX Functions te hi PHP 5.3 atanga hman tawh loh tura hluihlawn (depracated) an ni a. PHP 7-ah chuan paih vek an ni tawh a. Chung te chu: erec(), eregi(), ereg_replace(), eregi_replace(), split(),spliti(), sql_regcase() te hi an ni. PHP7-ah chian Perl-Compatible Regex (PCRE) functions an hmang vek tawh thung a ni. Mahse a mamawh tan chuan PECL atangin POSIX Regex hi install theih a ni vek bawk. PCRE-ah pawh hian paih an nei tho mai a, chu chu e modifier, preg_replace nena hman kawp thin hi a ni. Hei hi PHP 5.5 atang khan depracated a ni tawh nghe nghe. A aiah preg_replace_callback() function hman thung tur a ni.

Thil dang an paih leh chu PHP tag aia ASP tags hman theihna <% %> leh <%= %> te kha paih a ni a, HTML script tag <script language="php"></script> pawh paih tel a ni bawk. PHP 5.4 tang khan magic quote support tih tawp a ni tawh a. PHP7 ah chuan paih fai vek a ni. PHP.ini-a comment siam nan # symbol hman thin kha a tha lo tih an hmu chhuak leh tawh a, chuvangin ; (semicolon) chiah a hman theih tawh bawk.

Sawi tur tam tak a awm thei ang a, strict mode leh non strict mode a awm theih thu te hi chu topic ang deuh tawpa sawi zel a ngai tawh a. PHP7 i hmang dawn a nih chuan Error on vek a tha, error atanga inzir hi hriatnaah a cham rei bik a. Error hi developement-ah chuan ON ngei ngei tur a ni a, production-ah erawh OFF a tha zawk thung.
Error ON dan:

php.ini file-ah
display_errors=ON
error_reporting=E_ALL


php.ini file hi kan HOST-in kan edit theiha an dah loh pawhin kan server chuan Apache a hman chuan .htaccess hmangin error hi on theih tho a ni bawk a:

.htaccess file-ah
php_flag display_errors on
php_value error_reporting 32767


A tawp berah chuan PHP7-a thil thar langsar ber chu Zend Engine an siamthar PHPNG vanga a speed nasa taka an improve leh memory a mamawh tam lo hi a ni a; hei vang hian green version of php tia sawi a ni bawk.

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.