PHP and undefined variables strategy

前端 未结 12 1099
名媛妹妹
名媛妹妹 2021-01-17 09:49

I am a C++ programmer starting with PHP. I find that I lose most of the debugging time (and my selfesteem!) due to undefined variables. From what I know, the only way to dea

12条回答
  •  爱一瞬间的悲伤
    2021-01-17 10:38

    This is a common complaint with PHP. Here are some ideas:

    1. Use a code analysis tool. Many IDEs such as NetBeans will help also.

    2. Just run the code. PHP doesn't have an expensive compilation step like C++ does.

    3. Use unit testing. Common side effects include: better code.

    4. Set error_reporting(-1), or the equivalent in your ini file.

    5. Get xdebug. It's not preventative, but stack traces help with squishing bugs.

    6. isset(), === null (identity operator), and guard clauses are your friends.

    Loose and dynamic typing are a feature of the language. Just because PHP isn't strict about typing doesn't mean you can't be. If it really bugs you and you have a choice, you could try Python instead—it's a bit stricter with typing.

提交回复
热议问题