Home Backend Development PHP Tutorial What are the methods for php syntax checking? (code example)

What are the methods for php syntax checking? (code example)

Jan 12, 2019 pm 04:16 PM
php syntax

Grammar checking in php is very necessary. If the grammar is not checked, it will not work properly when an error occurs. If syntax checking is performed at the same time, the error may not occur. This article Let’s take a look at how to check PHP syntax.


What are the methods for php syntax checking? (code example)

We can use lint check

use lint static check.

Static is a method that only checks the syntax description method without executing the program.

Use the lint command at this time.

※php_check_syntax This syntax checking function has been abolished and cannot be used.

Then prepare the php file where the error actually occurs.

lint_test.php

1

2

<?php

echo "error"

Copy after login
Copy after login

It is just a code that displays error on the screen.

Move lint_test.php to a directory and issue the following command.

1

php -l lint_test.php

Copy after login

Execution result

1

PHP Parse error:  syntax error, unexpected end of file, expecting &#39;,&#39; or &#39;;&#39; in lint_test.php on line 2 Parse error: syntax error, unexpected end of file, expecting &#39;,&#39; or &#39;;&#39; in lint_test.php on line 2Errors parsing lint_test.php

Copy after login

syntax error=Output syntax error indication.

It also returns the error line number as line 2.

Because there is an unexpected end of file, the reason is that there is no ";" in the second line.

Then, modify lint_test.php and execute the lint command again.

1

2

<?php

echo "error";

Copy after login

The execution result is:

1

No syntax errors detected in lint_test.php

Copy after login

No syntax errors are displayed.

Use xdebug to dynamically check for syntax errors

First, enable xdebug.

① Download xdebug from the official site below, and note the path of the local environment where the downloaded .dll file is located.

https://xdebug.org/download.php

② Add the following content to php.ini.

1

zend_extension = ①中记录的路径

Copy after login

②Restart the Web server (Apache, etc.)

This completes the setting.

Use xdebug to check for errors

We run the lint_test.php used above.

lint_test.php

1

2

<?php

echo "error"

Copy after login
Copy after login

There is an error because there is no semicolon at the end.

The content is the same as when lint is executed, but with some decorations added for easier viewing.

The biggest difference with lint is the error that occurs after executing the code, so it can be said that the error occurs due to dynamic checking.

The above is the detailed content of What are the methods for php syntax checking? (code example). For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Getting Started with PHP: Basic PHP Syntax Getting Started with PHP: Basic PHP Syntax May 20, 2023 am 08:39 AM

PHP is a server-side scripting language that is used to develop dynamic websites, web applications, and web programs. PHP has a wide range of applications, and both beginners and experienced developers can benefit from it. This article will provide you with an introductory guide to the basic syntax of PHP. If you want to learn PHP programming and build a solid foundation from scratch, you've come to the right place. The basic structure of PHP. A PHP program contains the following three parts: &lt;?php//PHP code?&gt;& on both sides of the code

5 basic concepts that PHP beginners must know 5 basic concepts that PHP beginners must know Jun 21, 2023 am 10:24 AM

With the continuous development of Internet technology, PHP, as a Web programming language, is becoming more and more popular. PHP is widely used and can be developed using PHP from simple static websites to large e-commerce websites. Whether you are a novice who is just starting to learn PHP or a developer who already has some experience, it is very necessary to master some basic concepts. In this article, I will introduce 5 basic concepts that PHP beginners must know. Variables in PHP are containers used to store data. In PHP,

How to solve common problems in PHP: syntax errors and warnings How to solve common problems in PHP: syntax errors and warnings Jun 11, 2023 pm 04:13 PM

PHP is a widely used server-side programming language often used to build dynamic web pages. However, when writing PHP scripts, you often encounter various syntax errors and warnings. These errors and warnings can cause your code to not run properly or cause problems, so it's important to resolve them. This article will introduce common problems in PHP: syntax errors and warnings, and provide effective methods on how to solve these problems. Syntax Errors Syntax errors are a very common problem when writing scripts in PHP. Syntax errors may be due to the following reasons

How to effectively improve the level of PHP programming? How to effectively improve the level of PHP programming? Jun 12, 2023 am 08:57 AM

PHP is a language widely used in web development, and its popularity and usage rate are quite high. Many beginners will encounter some difficulties when learning PHP programming, such as not knowing how to improve their programming level. Below we will introduce some methods to make it easier for you to improve your PHP programming level. Learn the latest technology Internet technology updates very quickly, and PHP is no exception. If you want to become an excellent PHP programmer, you must first learn the latest PHP technology and master the latest Web development technology, such as M

PHP from beginner to advanced -- learn basic syntax and concepts PHP from beginner to advanced -- learn basic syntax and concepts Sep 09, 2023 am 10:01 AM

PHP entry to advanced - learn basic syntax and concepts Introduction: PHP (Hypertext Preprocessor) is a popular server-side scripting language widely used in Web development. In this article, we will start from the entry level, gradually learn the basic syntax and concepts of PHP in depth, and provide code examples for your reference. 1. PHP installation and configuration Before starting to learn PHP, you first need to install PHP on your machine. You can download it from the official website (https://w

In-depth analysis of the functions and characteristics of PHP arrow symbols In-depth analysis of the functions and characteristics of PHP arrow symbols Mar 22, 2024 am 09:54 AM

The arrow symbol (-&gt;) in PHP is a very important operator used to access the properties and methods of objects. This article will provide an in-depth analysis of the functions and characteristics of PHP arrow symbols, and provide specific code examples to help readers better understand their usage. In PHP, the arrow symbol (-&gt;) is mainly used to access the properties and methods of objects. When we create an object, we can access the object's properties or call the object's methods through arrow symbols. First, let's look at a simple example, create a class and instantiate

PHP development experience sharing: tips and suggestions for building efficient functions PHP development experience sharing: tips and suggestions for building efficient functions Nov 22, 2023 am 10:45 AM

PHP is a widely used server-side scripting language for developing dynamic web pages and web applications. Many websites and applications use PHP as their back-end development language, so having PHP development skills and experience is crucial to building efficient functionality. In this article, I will share some experiences and tips I have learned in PHP development, aiming to help developers improve their coding skills and ability to build efficient functions. Pick the right development tools and frameworks Before starting PHP development, pick the right development tools and frameworks

PHP introductory tutorial: basic syntax that beginners must master PHP introductory tutorial: basic syntax that beginners must master Jun 11, 2023 pm 09:45 PM

PHP is widely used in web development and is a server-side scripting language. Before learning PHP, we need to have basic knowledge of HTML and CSS. The following will introduce the basic syntax of PHP that beginners must master. Variables Variables are defined and assigned using the $ symbol in PHP, such as $variable="helloworld";. Variable names must start with the $ symbol and can only contain letters, numbers, and underscores. Variables in PHP have the characteristics of dynamic type and can store numbers and strings.

See all articles