Sunday, December 18, 2016

Format of auth.json needed to install Yii Framework

 {
    "http-basic": {},
    "github-oauth": {
        "github.com": "_TOKEN_"}
}

Friday, November 25, 2016

if ; if...else ; if ...else if...else , switch

To evaluate multiple expressions.

1. if Statement

if (condition)
  {

   }

2. if... else  Statement

if (condition)
  {

   }
else 
  {

  }

3. if... else if... else  Statement

if (condition)
  {

   }
else if
  {

  }

else
  {

  }


Use switch Statement to evaluate only one expression. executing different code according to the result of that expresiion evaluates to a simple type(a number, string or boolean)

switch (expression) {
 case result1;

 case result2;

default ;

}

Operators (PHP vs Clipper vs Delphi)

Comparison of OR/AND between Clipper/Harbour, Delphi and PHP.

1. OR

Clipper/Harbour  .OR.
Delphi                   OR
PHP                       .


2. AND

Clipper/Harbour  .AND.
Delphi                   AND
PHP                       &&

Thursday, November 24, 2016

Single Quote (' ') vs Double Quotes (" ")

Double quotation marks allow the parsing of variables.

Example

$name='"Chee"
print "Hello, $name ;  // Hello Chee

If you use a Single Quotation marks to enclose the same string, the variable is not substituted.

Example

$name="Chee"
print 'Hello, $name'  ;  // Hello, $name

Illegal Variables

PHP variables will be illegal if

a) contains a space
b) does not start with a leeter, or
c) contains non-alphanumeric characters

PHP 7 vs PHP

PHP 7 was released in December 2015.
The features of PHP7 are fairly enough for advance web application development and making use of latest resources to boost you development. There are lot of talks about PHP5.7, PHP6 or PHP 7. The main reason behind the PHP7 is PHP6 has never reached to stable version, also there are many resources available about PHP6. So PHP community has chosen PHP5.6 to directly PHP7.
Let us get into some details:-
1. Performance:
You might have heard about Facebook HVVM out there, to provide you maximum performance for PHP based application. So PHPNG (PHP-Next-Gen) started with the idea to provide maximum performance as Facebook HVVM provides. The performance improvement source was led by ZEND to speed up PHP based applications. As per Zend performance improvement is huge! You can find some benchmark against HVVM here. Without changing single piece of code, just upgrading to PHP7 gives you enormous performance. Deprecating many redundant features also part of performance improvement of PHP7.
2.Scalar Type Hints & Return Types:
While many developers would like able to declare return type for the function or method. By default PHP7 will allow developers to declare what kind of return type function is expected to return a value. It is almost similar as Type hinting parameters as below.
Example:
 public function isValidUser(int $id) : bool 
   {
     return isset($this->users[$id]) ? true : false;
   }
Above example is similar as Facebook HACK syntax. In this example bool indicates the function will return only boolean value. You can also have look at many example in RFC here. This allows developers to set expecting stringintfloat or boolean to be passed or returned.
3.Spaceship Operator
PHP7 will introduce a new operator called spaceship operator (<=>) otherwise called combined comparison operator. It can be used mostly in sorting and combined comparison. It works like strcmp() or version_compare().
As per the PHP RFC common uses of sorting as below.
Example:
Before PHP7:

function order_func($a, $b) 
{
  return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
}
then,
After PHP7:

function order_func($a, $b) 
{
  return $a <=> $b;
}
It is a beautiful addition to the PHP version. You can find more example here.
4.Additional Features
Apart from above changes there are few new features added into the PHP7 core. I am listing few major changes below.
  • Abstract Syntax Tree: – Another big change on the core. But most likely to be visible to developers. It makes parsing php code easier, less error, and way to build better things in future.
  • Closure::call() : – This is the new method added into core. It allows variable binding at call time rather pre-binding.
  • Null Coalesce Operator : – The coalesce operator or ?? added to the core, which returns the first operand if exists or null.
Example:
   //Before PHP7:

$id = isset($_GET[‘id’]) ? $_GET[‘id’] : null;

 In PHP7:

$id = $_GET[‘id’] ?? null;  //equivalent of writing old above syntax 
  • Uniform Variable Syntax : – The main deference of existing syntax and new syntax is to keep consistence and complete variable syntax. Allows advance expressions.
Example:
$$foo['bar']['baz']   interpreted as   ($$foo)['bar']['baz']
$foo->$bar['baz']()   interpreted as   ($foo->$bar)['baz']()
  • Unicode Codepoint Escape Syntax: – PHP7 introduced syntax to escape unicode codepoint as below.
Example:
echo "\u{202E}Reversed text"; // outputs ‮Reversed text
echo "\u{1F602}"; // outputs ��
5.Cleanups:
Developers can stop recognizing method name as class name to be a constructor as per PHP4 . It has been controversial early to remove but later has been removed completely as currently we no longer required to warn PHP developer how PHP4 works. This removal added as simplicity.
mysql_* functions are completely removed as extension removed by default.
Multiple default clause support has been removed from the switch case.
Support of ASP tags (<%) and script tags (<script language="php"></script>) has been removed meaning that you can't use those tags to enter php mode.
You can find more, list of deprecated or removed functionalities here, Removed deprecated functionalities in PHP7
Conclusion:
Personally I believe recent changes of PHP versions, makes PHP as much more matured language. But it is good message to all PHP developers for building awesome enterprise level applications using latest PHP version.

CREDITS


Sunday, November 20, 2016

What is PHP ?

PHP is a popular general-purpose scripting language that is especially suited to web development.
Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. 

<!DOCTYPE HTML>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>

        <?php
            
echo "Hi, I'm a PHP script!";
        
?>
    </body>
</html>


Instead of lots of commands to output HTML (as seen in C or Perl), PHP pages contain HTML with embedded code that does "something" (in this case, output "Hi, I'm a PHP script!"). The PHP code is enclosed in special start and end processing instructions <?php and ?> that allow you to jump into and out of "PHP mode." 

What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve. 

The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid reading the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours.