PHP 7 cool new features

Hello all,

Today, I thought to give you a quick run through about cool new features in PHP 7. PHP 7 has been there for sometime but it is still worth paying some closer look at what it has to offer to the world of PHP development. In this post I will be giving few examples which are exclusively to PHP 7 and onwards. Please note that at the time I write this post PHP 7.2.5 is available to download.

Scalar type declarations

Type declaration tells the type of the arguments needs to be passed when calling a function. Available scalar types are class, self, callable, array, int, string, float, boolean and iterable. (The latter five was introduced as part of PHP 7).

declare(strict_types=1);
function getTotal(int ...$ints)
{
return array_sum($ints);
}

var_dump(getTotal(45, 85, 134));

The above will give you this,

int(264)

With the strict_types enabled if you call the same function by passing mixed type parameters like this,

var_dump(getTotal("45", '8', 134.4));

This will give you a TypeError,

Fatal error: Uncaught TypeError: Argument 1 passed to getTotal() must be of the type integer, string given, Next TypeError: Argument 2 passed to getTotal() must be of the type integer, string given, Next TypeError: Argument 3 passed to getTotal() must be of the type integer, float given. 

For additional information, the declaration of strict type is per file basis and it will affect function parameter types as well as function return types. Continue reading

Share

Encrypt and Decrypt using OpenSSL in PHP

Hello all,

In this topic, I will be talking about encryption and decryption using OpenSSL in PHP. I will be briefly discussing what “two way encryption” is and how to use it in your PHP application using OpenSSL encrypt and decrypt methods with a readily usable example. At the end of this page there will be a zip file where you can download and run the example.

Two way encryption (encryption and decryption) is the simplest way of securely sending some sensitve information over the Internet using a shared secret key. To make things understandble picture this scenario. A web user fills a form with some data and press the submit button. When the form is submitted, data will go from place A to place B. If we send data as it is, anyone (i.e. Spy) has access to data packets can open and see what’s inside. So, before sending data as it is we will use a convertion method (encryption) to transform human readable data (i.e. Plain text) into a human unreadable format (i.e. Cipher text). Then the receiving end will perform a data convertion exercise (decryption) to transform data back to readable format.

(Image URL :- https://commons.wikimedia.org/wiki/File:Crypto.png)

Continue reading

Share

How to call an Oracle Function in Symfony 2

Hi All,

How are you doing? Seems like my fingers do not want me to stay away from Symfony2 despite the Spring Bank Holiday. 🙂

Today, I am going to talk about how to call an Oracle Function in Symfony2. A function (aka stored function) is a collection of SQL statements which is used to perform various different activities within the Database. The good thing about the function is you can write your chunks of SQL inside the function and call it using a name to initiate. I will be focusing on how to call an Oracle Function in Symfony2 and if you would like to know more about Oracle functions please click here.

First, let’s take a look at a sample function which I have created and is saved in Oracle 12c Database.

create or replace 
FUNCTION testFunc123(old_bname IN VARCHAR2) 
   RETURN VARCHAR2 IS 
   BEGIN 
      IF old_bname = 'TEST' THEN
          RETURN 'Y';
      ELSE
        RETURN 'N';
      END IF;  
    END;

The role of the above created Oracle function is to check whether the value of ‘old_name’ is equal to ‘TEST’ or not. If it is ‘TEST’, then the function will return ‘Y’ otherwise ‘N’. So, now what we going to do is call this function inside a Symfony2 controller. This is really easy, thankfully to wonderful Doctrine2.

Continue reading

Share

Gumball3000, London UK 2016

Hi folks,

How are you all doing? Last week, I got an opportunity to witness some hot, sports cars in Gumball3000. Gumball3000 was held on 2nd May 2016 (Bank Holiday) at Regent Street, Central London. That was quite fun and there were a plethora of expensive sports cars roaming through the Regent Street. I got some pictures during the event and I would like to share those images with you. Some of these images were taken by @gtiranda. Thanks Iranda for those images. Enjoy my PhotoBucket album below 🙂

Last but not least, I got my eyes lucky enough to see my childhood hero David Hasselhoff during Gumball3000 and here is the video that I have recorded 🙂

The official Gumball3000 URL :- https://gumball3000.com/

Cheers!

Share

Feeling

Hi everyone, this is a random thought which came to my mind when I was coming back home this evening. I hope you will enjoy 🙂

Feeling-Lost


[image:http://cdn.tinybuddha.com/wp-content/uploads/2014/07/Feeling-Lost.png]

Sinks our whole soul, when it arrives
Unshakable flow coming along, when it hits the pot
Turning down becomes a powerless effort
Dwelling too much isn’t too good as it steals yourself from you
You will forget your breath and largest rock goes unnoticed
Standing and walking becomes lighter than never before
But, flying is still an unachievable dream
People around you will try to show the easy way out
But, this is a battle between you and yourself
Looking down as you are counting shells on the beach
Your eyes will meet everything but no shells on the sand
Continue reading

Share