Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hello Zephir

Hello Zephir

Introduction to zephir lang.

Avatar for Nyan Lynn Htut

Nyan Lynn Htut

November 20, 2014

More Decks by Nyan Lynn Htut

Other Decks in Programming

Transcript

  1. The name Zephir is a contraction of the words Zend

    Engine/PHP/Intermediate (Pronounce is zaefire)
  2. Purpose • Easy to creation and maintainability for PHP Extension

    • Easy to contribute Phalcon PHP Framework
  3. What is Phalcon • The fastest PHP Framework • Full

    stack framework for PHP 5 written as a C-extension
  4. Hello World • Code in Zephir must be placed in

    classes • Intended to create object-oriented libraries/frameworks • Namespace is required
  5. Main features Type system dynamic/static Memory safety pointers or direct

    memory management aren’t allowed Compilation model ahead of time Memory model task-local garbage collection
  6. Compilation vs Interpretation • Compilation usually slows the development time

    • Need to compile before running your code • Interpretation reduce the performance in favor of productivity
  7. Statically Typed • A variable is bound to a particular

    type for its lifetime • Its type can’t be changed • Eg : C, C++
  8. Dynamically Typed • Type is bound to the value, not

    the variable • A variable might refer to a value of a type • Eg: PHP, JavaScript
  9. Compilation Scheme • Zephir compile and optimize to native code

    (C Language) • A compiler optimize and compile to machine code (gcc/clang/vc++)
  10. Code Protection • You can hide the code to user

    and customer. • You can hide the code to other programmer
  11. Taste /* Variables declaration */ var myData; int total =

    10, length; string name = “Zephir Language”;
  12. Taste // Assign value to variable let length = 5;

    // Create array let myDate = [1, 2, 3, 4];
  13. Taste of “Fetch” • ‘Fetch’ is an operator that reduce

    a common operation in PHP into a single instruction <?php if ( isset($myArray[$key])) { echo $myArray[$key]; } if fetch value, myArray[key] { echo value; }
  14. Taste of “Typeof” • This operator check variable type. ‘Typeof’

    could works like comparison operator if (typeof str == "string") { echo str; }
  15. Type Hints // Tell the compiler that "o" // is

    an instance of class MyClass let o = <MyClass> this->_myObject; o->myMethod();
  16. Return Type Hints • Methods in classes and interfaces can

    have return type hints namespace App; class MyClass { public function getSomeData() -> string { // This method must be return string value } public function getApp() -> <App\MyInterface> { // This method must be return object // does implement App\MyInterface } }
  17. Read-Only Parameters • Parameters marked with this attribute cannot be

    modified inside the method namespace App; class MyClass { // "a" is read-only public function getSomeData(const string a) { // this will throw a compiler exception let a = "hello"; } }
  18. Getter/Setter shortcuts • Like in C#, you can use get/set/toString

    shortcuts in Zephir namespace App; class MyClass { protected myProperty { set, get, toString }; }