Home  >  Article  >  Backend Development  >  What is the syntax difference between PHP and Java?

What is the syntax difference between PHP and Java?

Guanhui
GuanhuiOriginal
2020-07-24 11:52:592362browse

What is the syntax difference between PHP and Java?

What is the syntax difference between PHP and Java?

1. There are 8 basic data types in Java and corresponding reference types. PHP has no reference types;

2. There are method overloading under a class in Java. PHP Only methods of the parent class can be overloaded;

3. Java has the concept of internal classes, but PHP does not.

Other subtle differences

1.PHP is a scripting language, the code is executed on the server, and the results are returned to the browser in plain text.

2.PHP can run on a variety of different platforms: such as windows, linux, MaxOS, etc.

3.PHP scripts can be stored anywhere in the document, starting with .

4.PHP comments: PHP supports three comment methods:

A. Double slashes, for example: //This is to declare a variable

B.# symbol, for example : #This is to declare a variable

C./**/ For example: /*This is to declare a variable*/

Java also supports three comment methods:

A. Double slashes, for example: //This is to declare a variable

B./**/ For example: /*This is to declare a variable*/

C./***/ For example: /***This is to declare a variable*/

5. Case sensitivity issue in PHP: In PHP, all user-defined functions, classes and keywords (such as if, else, echo, etc.) are not case-sensitive, while variables are case-sensitive. of.

In Java, all function names, keywords, classes, variables, etc. are case-sensitive.

6. PHP variable declaration: PHP is similar to Javascript. Both are reference types, and there is no need to specify the type when declaring. Java is a strong reference type, and its type must be specified when declaring.

The way to declare variables in PHP is: $X = 7; Note: The naming rules for java and PHP variables are the same.

7. The scope of variables in PHP:

A. global (global): can only be accessed outside the function

B. Local (local): Can only be accessed within the method body

 C.static (static)

Global variables in Java are allowed to be accessed within the method.

8.global keyword: You can use the global keyword in the function body to access global variables.

Recommended tutorial: "PHP"

The above is the detailed content of What is the syntax difference between PHP and Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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