Simple Trait in PHP PRO
Defining a trait is very similar to defining a class. Instead of using the keyword class we use the keyword trait. The purpose of traits is to group functionality in a fine grained and consistent way. It is not possible to instantiate a trait. The trait servers as an additional capability that provides us with additional capabilities when […]
Arrays Short Syntax in PHP 5.4 PRO
As of PHP 5.4 we can create new arrays in a simple way. Simpler than ever. The following code sample shows that. <?php $vec_a = [4,6,2,7]; $vec_b = [‘a’=>’australia’,’b’=>’belgium’,’c’=>’canada’]; foreach($vec_a as $k=>$v) { echo ” “.$k.”=>”.$v; } foreach($vec_b as $k=>$v) { echo ” “.$k.”=>”.$v; } ?> The following video clip shows the execution of this […]
Array Dereference in PHP 5.4 PRO
As of PHP 5.4 we can develop a function that returns an array and treat the call to that function as an array we want to access its elements. <?php function doSomething() { $vec = [23,53,75,64]; return $vec; } echo doSomething()[0]; ?> The following video clip shows the execution of this code sample and explains […]
The PHP 5.2 filter_var Function PRO
PHP 5.2 adds the filter_var function. It is an important function that assists with validating the user input. <?php $email_address_dirty = “haim.michael@gmail.com”; if(filter_var($email_address_dirty,FILTER_VALIDATE_EMAIL)) { $email_address_clean = $email_address_dirty; } echo $email_address_clean; ?> The following video clip shows the execution of this code sample and explains it.
PHP 5.4 Short Tags PRO
As of PHP 5.4, the support for short tags exists by default. There is no need to introduce changes into php.ini in order to use the PHP short tags. <? $numA = 24; $numB = 4; ?> <h1><?=($numA+$numB)?></h1> The following video clip shows the execution of this code sample and explains it.
PHP 5.4 Access Members on Instantiation PRO
PHP 5.4 allows us to access class members on the instantiation. We will use this special capability in those rare cases in which the only reason for creating the object is in order to allow us to access one of the class members. <? class Utils { function calc($numA,$numB) { return $numA+$numB; } } $temp […]
Shenkar Programming Languages July 2012 ACD
During the coming summer semester (July-August, 2012) I will deliver the Programming Languages academic course in Shenkar. This course belongs to Shenkar’s BSc Academic Program in Software Engineering. You can find the google group of this course at https://groups.google.com/forum/?fromgroups#!forum/shenkar-programming-languages-summer-2012. You can find the detailed plan at https://docs.google.com/spreadsheet/pub?key=0AhDgrQD6qivLdDk3eG9KWVZvM3I2THJjRmpncXVkQXc&output=html. You can find the formal syllabus at http://www.lifemichael.com/shenkar/PROGRAMMING_LANGUAGES_COURSE_SUMMER_2012.pdf
Android Platform HIT Summer 2012 INFO
During the academic summer semester in HIT I am going to deliver an academic course for android applications development. The google group we are going to use in this course can be found at https://groups.google.com/group/hit-android-summer-2012. The syllabus can be downloaded at http://www.lifemichael.com/en/wp-content/uploads/2012/09/ANDROID_SYLLABUS_201207.pdf. The detailed plan ca be found at https://docs.google.com/document/pub?id=1Wq4dPoqVm80OuVTloLcfFp_l1vZV7N5hobfy1YvMR48. The final project the students are going […]
PHP 5.4 Class::{expr}() Syntax PRO
PHP 5.4 provides us with a new way to invoke static functions. This new way allows us storing the function name in a variable (as a string) and place that variable within curly brackets. <? class GoGo { public static function do_something() { echo “something!!!”; } } GoGo::{‘do_something’}(); ?> The following video clip shows the […]
The __get & __set Magical Functions in PHP PRO
Using these two functions we can dynamically add new variables, that weren’t defined in the class, to objects in our program. <? class Bongo { var $vec; function __construct() { $this->vec = array(); } function __get($str) { return $this->vec[$str]; } function __set($var_name,$var_value) { $this->vec[$var_name] = $var_value; } } $ob = new Bongo(); $ob->name=”balaboa”; $ob->id=12123123; echo […]