Once gives PHP Division By Zero Error

I'm trying to require a config file in index.php by using:

require_once __DIR__/application/common/config/Config.php;

However, PHP error logs state division by zero. The full path is /var/www/application/common/config/Config.php

How do I ensure this path is correctl represented in my require_once statement?


您需要使用PHP中的字符串引号...

require_once __DIR__ . '/application/common/config/Config.php';

require_once __DIR__ . '/application/common/config/Config.php';

that should work? The "." concatenates the string. Basically " dir " (plus) 'other values'. and the other values need to be in quotes, otherwise it will take "/" as a basic math operator, thus trying to divide everything by 0 in the rest of the statement.

(require_once DIR /0/0/0/0;) and you can't divide by 0 ;)


This happens because of a series of design mistakes in PHP.

  • PHP converts every symbol it does not know to a string, except it has a leading upper character, that will be a constant.
  • Constants that are not defined are NULL
  • When you try any mathematical operation on a string, it gets converted to an integer.
  • "123" will be 123
  • "123 abc" will be 123 as well
  • "abc" will be 0.
  • When you try any mathematical operation on NULL , it gets converted to 0
  • So what happens, is that PHP calculates "yourdirectory"/0/0/0/0 , which is a division by zero. (Ouch! Did I already tell you that PHP is a broken language?)

    Just put the string in quotes.

    require_once __DIR__."/application/common/config/Config.php";
    
    链接地址: http://www.djcxy.com/p/69362.html

    上一篇: 我如何抑制Swiftmailer错误?

    下一篇: 一旦给出了PHP分区错误