PHP or Java Script?

deadimp

New Member
Messages
249
Reaction score
0
Points
0
Javascript - Easy To Use - Less Powerful And Less Functional.
PHP - Difficult To Use- More Powerful And More Functional
PHP and JS both have their own specific attributes that are catered to their 'audience'.
PHP is meant for server-side request processing, as everyone has pretty much said.
JS is meant for client-side interaction and processing. It can interface directly with the DOM, as well as do its own thing.

I don't think it's applicable to say one's more powerful than the other.
As I said, they have their distinctions. Most notably with PHP, there's sigils with string parsing, and a large library of functions available to the user. Plus, you have a semi-strong OOP structuring available.
Code:
$x=145;
$str="A string...";
function stuff($a,$b) {
 echo "Concatenate \"$a\" and \"$b\"<br>";
 return $a.$b;
}
$str=stuff($str,$x);
$list=array(5,4,"Bob",$str);
print_r($list);
echo "<br>";

class Test {
 var $x;
 static $something="Static value"; //PHP 5 only
 function __construct() {
  //Initialize
 }
 function method() {
  return sqrt($this->x);
 }
}
$tim=new Test();
echo $tim->method()."<br>";
$obj=(object)array('x'=>15,'name'=>'Bob');
echo "$obj->name $obj->x <br>";
$var='name';
echo $obj->$var;

In Javascript, it's notable feature is the way that how it handles functions as objects, and the ease in which you can define anonymous functions.
For example:
Code:
function myFunc(x,y) { blah blah blah };
//Or
var myFunc=function(x,y) { blah blah blah };
Both do the same thing. And you can have variables inside the function, and you can make a psuedo-OOP structure such as:
Code:
function Test() {
 //Instance-level members / methods
 this.x=5;
 this.method=function() { return Math.sqrt(this.x); };
}
//Statics
Test.something=function() { return "Static function"; };

var tim=new Test();
tim.method();
JS also has the ever-popular JSON (JavaScript Object Notation), ie:
Code:
var tim={x: 2, array: [5,2,"Bob"], method: function() { return this.array[this.x]; } };
tim.method();
//You can also access the members as an array index - tim["name"]

As for types, both are relatively relaxed and dynamically typed. With PHP, you do have the option to restrict types in your function arguments, but it's not used in extremely common code.

If you want to see how powerful Javascript is, download a popular library, such as jQuery, Prototype, or what not, and see what all it can do.

There's more that I haven't touched, and you can look into that yourself.
 
Last edited:

trebor

New Member
Messages
35
Reaction score
0
Points
0
blend the to of them and call it awesome...
I'm a fan of AJAX...
 
Top