Difference between PHP and Javascript

If you dont know every language has it’s own syntax. Let me start by pointing out why javascript has advance syntax.

Difference between creating objects

PHP


<?php
// Define an array.
$foo = array(); // New empty array.
$foo = array('a', 'b', 'c'); // Numeric index.
$foo = array('a' =&gt; '1', 'a' =&gt; '2', 'c' =&gt; '3'); // Associative.

// Define an object.
$bar = new stdClass(); // New empty object.
$bar->a = '1';
$bar->b = '2';
$bar->c = '3';
?>

Javascript 

// Define an array (longhand).
var foo = new Array(); // New empty array.
var foo = new Array('a', 'b', 'c'); // Numeric index.

// Define an array (shorthand, more common).
var foo = []; // New empty array.
var foo = ['a', 'b', 'c']; // Numeric index.

// Define an object.
var bar = {}; // New empty object.
var bar = {   // New populated object.
  a: '1',
  b: '2',
  c: '3'
};

A simple prototypal inheritance with javascript syntax that is quite difficult to do with PHP.

var Person = {
  greet: function () {
    return "Hello world, my name is " + this.name;
  }
};
var frank = Object.create(Person);
frank.name = "Frank Dijon";
frank.greet();

You can use the Prototype Creational Pattern to achieve something somewhat similar to this, but real prototypical inheritance like found in JavaScript is not possible with PHP (as far as i know).

Conclusion: PHP is now following javascript design pattern