Home > Web Front-end > JS Tutorial > What is the difference between php and js_Basic knowledge

What is the difference between php and js_Basic knowledge

WBOY
Release: 2016-05-16 17:26:48
Original
1592 people have browsed it
1. Differences in type conversion

In javascript

empty objects and empty arrays are converted to boolean values ​​and are true;

But in php

The empty array of empty objects is converted to a boolean value of false;

(only in php4, the boolean value of the empty object is false)

Including non-0 negative values, all are converted is true;

2, the difference of actual formal parameters

In js, there is no limit to the number of formal parameters and actual parameters. The number of formal parameters can be Greater than the actual parameters, or less than the actual parameters

In PHP, if the actual parameters are greater than the formal parameters, no error will be reported, but when the number of actual parameters is less than the number of formal parameters (and unspecified formal parameters are not An error will be reported when defining)

Copy code The code is as follows:

function mao( val1,val2,val3){
}
mao(aa,bb);


At this time, since val3 does not specify actual parameters, an error will be reported
but when val3 When initializing a value, no error is reported
Copy the code The code is as follows:

function mao(val1, val2,val3="123"){
}
mao(aa,bb);


You can write a ternary expression in js to give the unassigned form The parameter is given an initial value, which cannot be assigned in the formal parameter list like PHP.
The essential reason is that PHP does not have a prototype connection and there is no variable object during execution.

3. Differences in data types

There is an undefined type in js, but there is no such type in php,

So when a variable is not assigned any value When, this type is undefined in js (an error will be reported when using undeclared variables), but it is Null type in php;

and there is only number type in js, but there is no such type in php, replaced by It is int float type;

4. String connection

Use plus sign in js =

Use dot sign in php..=

5. The difference between control statements

else if and elseif are both supported in php, js only supports the former

6. Upper and lower case Problem

js is strictly case-sensitive

Custom function names in php are not case-sensitive. When naming a function, you cannot use declared functions or PHP's built-in function names.

7. Scope of variables

Variables declared by PHP outside the function scope are global variables. Since the function can be regarded as a separate
program fragment, local variables will override the visibility of global variables, so there is no
method to directly call and use global variables in the function. When you want to use a global variable in a function, you must use the global keyword to define the target variable, and use
to tell the function body that this variable is global.

js can directly call

8. Static variables

PHP supports declaring function variables as static (static)

js does not have static variables, but you can define attributes of functions to pretend to be static variables
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template