Bug and Debug in PHP

The program rarely works correctly right from the first time. Many things can be wrong in the program causing the PHP interpreter to generate an error message. You can choose where this error message appears. Messages can be sent along with other program output to the web browser. They can also be included in the error log on the Web Server.

To make the error message appear in the browser, set the directive to display__errors to On . To send errors to the error log on the Web Server, set log_errors to On. If you want to report an error at both locations, you can set these two directives to On.

PHP defines a number of constants that you can use to set the value of error_reporting , so that only specific error types are reported: E_ALL (for all exceptions except strict notice), E_PARSE (parse error), E_ERROR (Fatal error), E_WARNING (warning), E_NOTICE (notice), and E_STRICT (strict notice).

While writing PHP programs, using editors that can identify PHP like BBEdit or Emacs is a good idea. One of the special features of these Editor is syntax highlighting. It changes the color of different parts of the program based on what those parts are. For example, PHP strings are pink, keywords like if PHP, while are blue, comments are gray, and PHP variables are black.

Another feature is matching quotes and parentheses, to ensure that your citations and parentheses are balanced. When you type a close parenthesis, for example}, Editor will highlight the opening parenthesis {matches it.

Dưới đây là các điểm quan trọng cần kiểm tra trong khi debug chương trình của bạn: Here are the important points to check while debugging your program:

  1. Thiếu dấu chấm phảy (;): Mỗi lệnh PHP kết thúc với một dấu chấm phảy (;). Missing semicolon (;): Each PHP command ends with a semicolon (;).PHP không dừng đọc một lệnh tới khi nó gặp một dấu chấm phảy. PHP does not stop reading a command until it encounters a semicolon.Nếu bạn quên dấu chấm phảy ở cuối dòng, PHP tiếp tục đọc lệnh trên dòng tiếp theo. If you forget the semicolon at the end of the line, PHP continues to read the command on the next line.
  2. Không đủ dấu bằng (=) : Khi bạn hỏi hai giá trị có bằng nhau không trong một lệnh so sánh, bạn cần hai dấu bằng (==). Not enough equals sign (=) : When you ask if the two values ​​are equal in a comparison command, you need two equals (==).Sử dụng một dấu bằng là một lỗi phổ biến. Using an equal sign is a common error.
  3. Tên biến viết sai chính tả : Nếu bạn viết sai chính tả một biến thì PHP hiểu nó như là một biến mới. Misspelled variable name : If you misspell a variable, PHP understands it as a new variable.Nhớ rằng, với PHP, $test và $Test không giống nhau. Remember, with PHP, $ test and $ Test are not the same.
  4. Thiếu ký hiệu $ : Quên ký hiệu $ trong tên một biến là hiếm khi gặp, nhưng nếu thiếu, nó sẽ tạo một thông báo lỗi để bạn biết nơi xảy ra vấn đề. Missing $ symbol : Forgetting the $ symbol in a variable name is rare, but if it is missing, it will generate an error message so you know where the problem occurred.
  5. Vấn đề về trích dẫn : Bạn có thể có quá nhiều, quá ít trích dẫn hoặc bị lỗi trích dẫn. Citation problem : You may have too many, too few citations or excerpt errors.Vì thế bạn nên kiểm tra thật kỹ các trích dẫn. So you should carefully check the citations.
  6. Thiếu dấu ngoặc đơn hoặc dấu ngoặc ôm : Các dấu ngoặc này luôn đi kèm thành một cặp (), {}, []. Missing parentheses or parentheses : These brackets are always enclosed in a pair (), {}, [].
  7. Array index : All arrays start at 0 rather than 1.

Also, handle all errors appropriately and send all trace messages into the system log file, so that if any problems occur, it will be written in log file and you can debug that problem.

Follow tutorialspoint

Previous lesson: Regular Expression in PHP

Next lesson: Date & Time in PHP

3.5 ★ | 2 Vote

May be interested

  • Learn about Opera page: of Opera browserLearn about Opera page: of Opera browser
    in the previous articles, we introduced you to some features of the about page in firefox browser, chrome: // chrome page, and this time we will continue with the opera: page of opera browser. . here, you can find many options to intervene, edit the specifications related to performance as well as stability.
  • How to set up ADB / USB Drivers and Fastboot for Android devicesHow to set up ADB / USB Drivers and Fastboot for Android devices
    adb is often used when trying to run phone applications on a computer, so you can debug (debug) errors on your applications, the application you are creating. and fastboot is used more by manufacturers to diagnose and repair devices that are having software problems.
  • How to fix Android not connecting to Windows via ADBHow to fix Android not connecting to Windows via ADB
    adb not working or detecting your device on windows? if android can't connect via android debug bridge (adb), fixing this error requires just 3 basic steps.
  • How to use ADB and Fastboot on AndroidHow to use ADB and Fastboot on Android
    adb is often used when trying to run phone apps on a computer, so you can debug errors on your apps, the apps you're creating. and fastboot is used more by manufacturers to diagnose and repair devices that are having software error problems.
  • Top 21 ADB commands Android users should knowTop 21 ADB commands Android users should know
    android debug bridge (adb) is a powerful and flexible tool that allows to do many things like find logs, install and uninstall apps, transfer files, root and flash custom roms, create backups device.
  • How to Lock Bootloader on AndroidHow to Lock Bootloader on Android
    today's tipsmake will show you how to use android debug bridge (adb) for windows to unlock the bootloader - the program that boots the system and the pre-installed operating system on android devices. warning: this method has the potential to reformat the device. make a backup before doing so.
  • Managing log files of Exchange Server 2007 - Part 2Managing log files of Exchange Server 2007 - Part 2
    in this article, i will show you some other ways to get log information in exchange server 2007.
  • Fix SVCHOST.EXE application with error 0x745f2780Fix SVCHOST.EXE application with error 0x745f2780
    suppose we have windows xp professional operating system with the password set for the administrator account. when we turn on the computer and enter the login screen. then the above error message appears. the only two options allowed with this error message are ok to end the program or cancel to debug the program.
  • Manage the Exchange Server 2007 log files - Part 3Manage the Exchange Server 2007 log files - Part 3
    in this section we will show you how to manage the recording of information on exchange connectors, message tracking, anti-spam agents and message records management features.
  • How to Determine Coordinates on MinecraftHow to Determine Coordinates on Minecraft
    minecraft tracks your location in the world using a coordinate system. these coordinates are hidden in the debug screen of minecraft desktop version. on handheld consoles, the coordinates will appear when you open map. if you're playing minecraft pe, you can specify coordinates as long as cheats are enabled in the world.