Update0815: Adjust the order of some contents Luo Wei put it in the back update0521: Add OO ideas Update0417: Slightly fix some views, add some content, but content is still more chaotic
The simplest no one will debug (?): Originally installed php is no problem, but also copied some code from the book to find can't be used, then use your eyes to carefully correct the code. It is definitely you copying wrong or printing is wrong, such as 1 (yi) with l (el) 0 (ling) and o (uppercase O), don't laugh, I have a mistake, I have made me in the past, I'm going to make it in the past. I entered in. (His no saving) is all right to return to Zheng Chuan Q: "Why is it to debug?" A: Of course because the program is wrong. Do you think I have any other answer? Q: "But I think my procedure should be right. ! "A: The result that can't be expected is of course wrong. People with this kind of thought are at all, there is no debugging ability. Q: What is the use of the call? A: Whether it is your configured PHP error or you The program is wrong or the correct program you write is configured with PHP (such as free space), and you can find out the reason for the reason. Q: Logic is chaotic, can you debug? A: Maybe you occasionally change I have changed, I thought it was called. In fact, it was not a simple debugger, but repeatedly used program code to think, and repeated changed code "Practice" is feasible. It can be said to be "debug logic" Non-"debug code": logic is not code or chaotic code - debug / modification logic -> The correct logic -> reflect on code, out of the correct code. Simply debug code is: correct logic - encoding - > Error code - debugging -> The correct code is debugging can be divided into: 1. Debug logic, 2. Debug code, 3. Debug interface. 4. Etc .. Error logic is impossible to come out the program. Write the program first, you have to make the logic (procedure), then start coding. Merge together is: Vagious logic - debugging logic -> Correct logic - Code -> Error code - debugging code - debugging code > The correct agent Ama's debugging logic You can use "Modify Code" to assist the brain is too tired, but the brain must move, can not think about the chaos, and cannot be mixed with "debug code". Change the mistake It is often solved, but it is necessary to make a lot of habits. Don't panic about the big mistakes. Don't panic, I will panic, I only know "I can't ask for a person." Asked, I have to calm down, according to the knowledge you have learned, what is debug, how to debug, I have to do something basic debugger: 1. Open the debug function: php.ini Set Error_Reporting = E_ALL and Display_ERRORS = ON Restart Web Service (Apache) 2. Refresh the error page to view the error prompt line number file name 3. Open this The file is positioned to the error line. For example, the code echo $ ABC [2]; 4. Understand error: a. View manual understanding error Meaning to understand the first thing to understand language, such as the simplest undefined index 2 means that the array does not exist It means that you have visited an element bless b. If you already know how to change it, you have changed directly, this is changed to ECHO $ ABC [0]; c. I don't know if the contents of the variable are added in the same place to join var_dump ($ ABC) ); Refresh page to see what element D. I think there is a $ ABC [2], then look for the wrong source, go back, or use var_dump (debug_backtrace ()); necessary VAR_DUMP ($ _ post, $ _get, $ _cookie, $ _server ....) I have not used Single Step (Step By Step) If the use of the debugger is relatively simple, it can be paused to see the contents of the variable. Is it medium? The value that should appear, if not, what is the attention of this value, what is the environment environment: Why is there more than a few people around the world? Do you have any questions? Your problem is in love with you or you love your problem? In fact, "one side of the water and soil", your "environment" raises your BUG. Usually read book / manual, pay attention to the record, what is "environment"
$ _ Get $ _POST $ _SERVER This is the critical factor of the program running, of course, $ globals you have come out, you can look at the content of var_dump them. There is a strtolower / strtoupper and setlocale () The function is related, and the default value is related to Getenv ("LANV") GetENV ("lc_all") under Linux (Putenv is not necessarily the configuration.) Also has a configurement of php.ini. Apache supports certain functions and does not support BTW1 under other servers: Your debugging ability is integrated with your coding ability, according to your code experience, what else you think can be mentioned BTW2: Some You may feel very simple and normal, but think about yourself is really doing ------------------------------------------------------------------------------------------------------------------------------------------------- - The following contents are more than the problem that you can see for you, of course, you can solve it immediately, but if you don't have a picture, you will be referred to: debugging the big direction: grab! A. The thief first smashes the king, the biggest mistake is logical error, First review the logic, then the key part of the code (with the error may be related) b. Shunan striking roots .. If there is a result, know the "result" of the final mistake, you can happen "Cause", such as if ($ logined) = 100;} $ _ session ['a'] = $ a; prompt undefined variable $ a, obviously to find a place to generate $ A, find IF The block found that only if true, there is only $ A to change to if ($ logined) {$ A = 100;} else {$ A = 0;} For example, Mysql's function error has a lot of prompts to prompt password error: Take a look The password of the parameter is wrong or the password of the mysql server setting is wrong. The SQL field does not exist. Open phpMyAdmin to see which fields have been written wrong or forget to add or do miss the table, the prompt statement is wrong, find mySQL manual Not a PHP manual! The so-called a heart, what is one of the "huge" code, so we have to come to "vice versa", separate the error from the code, and remove multiple errors On this way, for you is just a small number of mistakes, one by one. Remember to think about it before, how to solve it at that time. If you didn't recall, then You should find a new method. For beginners, Repeated exercise is important, recalling the ability to strengthen the ability to learn, until the joint will go through, apply it, comparison: The difference is similar to this article, it is to find the right code to compare. Sometimes there is no corresponding correct code, At this time, I can re-conceive a correct code in my mind. It is a bit difficult to avoid it. This is to avoid the wrong ideas. I want to see the manual. I don't know how it should be, according to the manual. Require your program comparison oo (not necessarily an object, but there are OOs on the structure / ideas) OO programming is an object, each type of object completes a feature, just like a mouse only needs to eat, you can live. An object / or some code only needs to work properly .oo debug method is the first thing to have: I have a certain data (OR code) only need to have some data (environment) Normal job If 1. Normal data is also wrong, it means that this object is designed. 2. The incoming data is abnormal, then the code call to use this object is wrong, and this is very "stupid", in fact Beginner (including the previous me) to form such a concept and use this concept to debug, but it is going to get close to the master after a long time. It is a bit like 'demolition' method but the difference is when debugging: 1. Take the object Out, you can debug separately because a good object (Or code) only needs to be as simple as possible, complex data may survive within or outside, without cross-out / into the object (that is, it will not pass it. Go out) 2. For web to quickly debug, do not have to take all the object's code, just call some of the object to add some to the object statement, such as var_dump ($ obj) var_dump ($ obj-> myabc) );