What are the differences between php and js? _ PHP Tutorial

Source: Internet
Author: User
What are the differences between php and js ?. 1. for different types of conversions, convert javascript empty objects and empty arrays to a boolean value of true, but convert php empty array to a boolean value of false; (only for the php4 hollow object
1. type conversion

In javascript

Convert an empty object and an empty array to a boolean value of true;

But in php

Convert an empty array of an empty object to a boolean value of false;

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

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

2. different parameters

In js, there is no limit on the number of form parameters and real parameters. the number of form parameters can be greater than or less than that of real parameters.

In php, if the real parameter is greater than the actual parameter, no error is reported, but when the number of real parameters is less than the number of actual parameters (and if the unspecified parameter is not defined, an error is reported)

 

However, when val3 initializes a value, no error is reported.

 mao(val1,val2,val3="123"

Essentially, because php does not have a prototype connection, there is no variable object during execution.

3. different data types

Js contains the undefined type, which is not available in php,

Therefore, if a variable has not been assigned any value, this type in js is undefined (an error will be reported when undefined variables are used), and Null type in php;

In addition, js only has the number type, but php does not. Instead, it replaces the int float type;

4. string connection

Use the plus sign ++ = in js

Use the dot in php... =

5. Differences in control statements

Else if and elseif are supported in php. js only supports the former.

6. case sensitivity

Js strictly Case Sensitive

Custom function names in php are case insensitive. You cannot use declared functions or PHP built-in function names when naming a function.

7. Scope of the variable

The variables declared by php outside the function scope are global variables. Since functions can be considered as separate
Program fragment, so local variables will overwrite the visibility of global variables, so there is no
Use global variables. To use global variables in a function, you must use the global keyword to define the target variable.
Tells the function body that the variable is global.

Js can be called directly due to prototype connection.

8. static variables

PHP supports declaring function variables as static)

JavaScript can impersonate static variables with no static variables but can define the attributes of functions.

Convert an empty object and an empty array in javascript to a boolean value of true, but convert an empty array of an object in php to a boolean value of false; (only in php4 hollow object...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.