: Follow us
Blog Ocean
  • Home
  • Blog
    • Technology
    • Women >
      • Contest
    • Fiction
    • Personal / Daily Life
    • News and Media
    • Sports
    • Religion
  • Guestbook
  • Contact

PHP 5.5: What’s New?

24/1/2014

0 Comments

 
PHP 5.5 is the latest version of the language bringing about many exclusive features to increase its efficiency. The changes have contributed to improve its performance and the developers have been privileged immensely. Some of The exciting features and the outcomes are briefly discussed here.

list() support by foreach statement:

It introduces list () support for foreach statement. While working with nested arrays, you can unpack the array elements into variables in each iteration via list().

$product = [
    ["Nokia", "Lumia"],
    ["Samsung", "Galaxy"],
    ["Apple", "iPod"],
];

foreach ($product as list($Brand, $device)) {
   
    echo "Brand: $Brand; Device: $device\n";
}


Output:

Brand: Nokia; Device: Lumia
Brand: Samsung; Device: Galaxy
Brand: Apple; Device: iPod

Generator Support

Generator provides an alternative way to implement iterator without implementing the iterator interface and thus remove the overhead of iterator. Generator is very similar to a function, difference is instead of returning value, it yields its value. The keyword yield is used for this purpose.

<?php
function generatorTest() {
    echo "Generator starts\n";
    for ($count = 1; $count < 6; $count++ ) {
        yield $count;
        echo "count: $count \n";
    }
    echo "Generator ends";
}
foreach (generatorTest() as $gen);
?>


Output:

Generator starts
count: 1
count: 2
count: 3
count: 4
count: 5
Generator ends

Array and string dereferencing support:

PHP 5.5 adds support for array dereferencing into individual element as well as string dereferencing into individual characters.

<?php
echo 'Array dereferencing example:';
echo [
0, 1, 2][0];
echo 
"\n";

echo 
'String dereferencing example:';
echo 
'Web'[0];
echo 
"\n";
?>

Output:
Array dereferencing example: 0
String dereferencing example: W

Finally keyword for exception handling:

In php 5.5, finally keyword has been introduced for exception handling. In previous versions, exceptions were handled by try catch block only, no finally block was available.  The finally keyword is followed by a block of code, which is placed after every catch block. This block of code will always be executed, however any exception is thrown or not.

function division($x,$y) {
    if ($y==0)
 {
        throw new Exception('Divide by zero');
             }
 return $x/$y;
}
try {
             echo division(10,0) . "\n";
} catch (Exception $ex) {
 echo 'Caught exception: ',  $ex->getMessage(), "\n";
} finally {
   echo "Finally block after division.\n";
}


empty()  function support for expression:

In previous versions, empty() function was able to only check value of a variable, by taking a variable as an argument. Now any expression can be used as argument in empty function to perform the same stuff.

<?php
$ a = 5;
$b = 8;

function check_val() {
if(($a - $b) > 0)
                        return 
true;
else
return 
false;
}
if (empty(check_val ())) {
    echo "False returned.\n";
}
else
echo "True returned.\n";
?> 

Output:
True returned.

New password API:

This version introduces a secure password hashing API, which is one of the most important contributions. Previously, we had to depend on crypt() function and md5 technology which lacks security and is somewhat confusing.  In new API, hashing is performed by bcrypt() function, which returns a strong hash with automatically salted. PHP 5.5 introduces two new function named password_hash() and password_verify().

New features in GD library

PHP GD extension has improved its ability with some advanced image operations. Here is a list of new functions for image  different operation:
  • Imageflip() : Provides image flipping support
  • Imagecrop() and imagecropauto() : Provides advanced image cropping support
  • Imagecreatefromwebp() and imagewebp() : WebP read and write support

The introduction of new features in PHP 5.5 has contributed greatly to upgrade the language and PHP development.

Read also introduction to HTML5.

0 Comments

Introduction to HTML5

24/1/2014

0 Comments

 
HTML5 coding canvasOutput: Html5 coding for Bangladesh flag
HTML5 for web design

HTML5 is the new standard for Hypertext Markup Language (HTML), where 5 mean it is the fifth revision of HTML.

Why HTML5 is better:
  • HTML5 and javascript are interpreted.
  • Cross-platform support
  • Mobile device support
  • No need for software updates
  • Mobile development

New Elements:
HTML5 introduces some new elements for
  • Structure
  • Media
  • Form
  • Canvas

New structure element in Html5:
<article>
<aside>
<bdi>
<command>
<details>
<dialog>
<summary>
<figure>
<figcaption>
<footer>
<header>
<mark>
<meter>
<nav>
<progress>
<ruby>
<rt>
<rp>
<section>
<time>
<wbr>

New media elements in Html5:
<audio>
<video>
<source>
<embed>
<track>

New form elements in Html5:
<datalist>
<keygen>
<output>

 Some new types have been included as form input type.
         tel
         search
         url
         email
         datetime
         date
         month
         week
         time
         datetime-local
         number
         range
         color

New canvas element:
<canvas>

Obsolete Elements:
Some former elements have been obsolete in HTML5:
<acronym>
<applet>
<basefont>
<big>
<center>
<dir>
<font>
<frame>
<frameset>
<noframes>
<strike>
<tt>

New API:
Some new APIs have been introduced in HTML5. Out of them, here is a list of some useful API.

Application Cache API  : Interact with application cache. The method window.applicationCache is used to get ApplicationCache object. 
Data Transfer API: Performs drag-drop operations.
History API : Provides browsing session history.
Media Controller API : Interact with <audio> and <video> elements.
File API: Performs file upload and file manipulation.
File Write API: Performs file write operation from web application.
Geolocation API:  Retrieves geolocation information for a client device.

Introduction to a very Exciting Feature of HTML5: Canvas

Canvas is one of the most exciting features for web design using HTML5. It is used to draw graphics element in web page on the fly using the scripting language.  Here is a brief discussion on how to create and use canvas in webpage.

Create a canvas using the following tag.
<canvas>

You have to fix the width and height of the canvas. Initially it is blank.
 <canvas id="canvas" width="150" height="150"></canvas>

Next the rendering context is needed to be accessed and draw something on it. At first retrieve the canvas DOM node using the getElementById method. We can then access the drawing context using thegetContextmethod.

var canvas = document.getElementById(canvas);
var ctx = canvas.getContext('2d');

For error handling, we can first check whether browser supports the canvas:

      var canvas = document.getElementById(canvas);
if (canvas.getContext){
  var ctx = canvas.getContext('2d');
  // drawing code
} else {
  // canvas-unsupported code
}



Then we can draw something on the canvas. As for example, we can draw a rectangle and a circle on the canvas. You can draw shapes on your canvas which is very useful for web design.

if (canvas.getContext){
  var canvasCtx = canvas.getContext('2d');

ctx.fillStyle = "rgb(0,255,0)";
        ctx.fillRect (10, 10, 60, 50);

                ctx.beginPath();
      ctx.arc(40, 35, 15, 0, 2 * Math.PI, false);          
                ctx.fillStyle = 'red';
      ctx.fill();
      ctx.lineWidth = 0;
     // ctx.strokeStyle = '#003300';
      ctx.stroke();
} else {
  // canvas-unsupported code
}


Make it all together. It draws the national flag of Bangladesh on the canvas.

<html>
 <head>
  <script >
    function draw() {
      var canvas = document.getElementById('canvas');
      if (canvas.getContext) {
        var ctx = canvas.getContext("2d");

        ctx.fillStyle = "rgb(0,180,0)";
        ctx.fillRect (10, 10, 60, 50);
         ctx.beginPath();
         ctx.arc(40, 35, 15, 0, 2 * Math.PI, false);    
         ctx.fillStyle = 'red';
         ctx.fill();
         ctx.lineWidth = 0;
      }
    }

  </script>
 </head>
 <body onload="draw();">
   <canvas id="canvas" width="150" height="150"></canvas>
 </body>
</html>


Output:


The new features and new API’s introduced by HTML5 reflects to a revolutionary change to the worldwide web. Hopefully, from the above discussion, you have got some ideas about the power of HTML5. Enjoy the vitality of HTML5 and use it for your business, development or whatever you do.

Read new features in PHP5.5 as well.


0 Comments

Android Project Structure

20/1/2014

0 Comments

 
Android app development - Android project structure 1
Apps and game development in android is a very promising profession now-a day. One must know Android project structure if they want to develop the career in Android based development.

Create a new project:

First, we would create a new project using eclipse. In different steps of project creation, we will configure the application which will affect some of our project configuration files.

 Step 1: File->new->project->android application project

Here, we have namedour application, package name under which the application will run; build sdk version and minimum sdk version. Minimum sdk version is required to make your application backward compatible, i.e. to run into previous android OS based device.


Read More
0 Comments

Android Apps Development : Working with bitmap image

23/12/2013

0 Comments

 
Android app development - bitmap image 1
Playing with image is always a fun. Now we are going to explore this type of fun in android. Have you ever played a game where part of a picture is shown to you and you are asked whose picture is it? Our target is to develop such an app in android with bitmap image.


Clue 1:

Android app development bitmap image 2




Clue 2:

Android app development bitmap image 3




Clue 3:

Android app development bitmap image 4




Clue 4:


Read More
0 Comments

    RSS Feed

    Author

    Vaibhav O Yadav - Top IT professional. Worked with Fortune 100 company. I like to spread the knowledge. Analyse situation and environment with long term vision and solution. Firm believer of sustainable development for earth. Apart from from being geeky also like to play multitude variety of video games on greater stretch of time with favorite being economic simulation

    Categories

    All
    Android
    Android App Development
    App Development
    Apple
    Cloud
    Data Virtualization
    Data Warehouse
    Virtualization
    Wordpress

    Archives

    October 2014
    March 2014
    January 2014
    December 2013

    Tweets by @BlogOcean

Home

Blog

Guestbook

Contact
Follow @BlogOcean

© 2013 - 2014 BlogOcean HQ
All rights reserved.