Reputation: 13005
I'm using PHP for my website. In one of my configuration files I'm defining a constant as follows:
define('CORE_PATH', BASE_PATH.'\core');
In another file I'm using this constant in a filepath configuration as follows:
require_once( CORE_PATH."\functions\common.php" );
But it's not working it's taking as
C:\wamp\www\smart-rebate-web\coreunctions\common.php instead
of
C:\wamp\www\smart-rebate-web\core\functions\common.php
I'm not getting mhy this is happening and how to make this thing correct so that the proper path should set in confgiuration file? The value of CORE_PATH constant is as below:
C:\wamp\www\smart-rebate-web\core
Than ks in advance.
Upvotes: 1
Views: 48
Reputation: 674
I'd start with replacing this:
require_once( CORE_PATH."\functions\common.php" );
with this:
require_once( CORE_PATH.'\functions\common.php' );
The reason is that your string is with double quotes, and inside double quotes, \f
means formfeed (hex 0C), according to the PHP manual. At the same time, \c
isn't a special sequence, so the end result is unctions\common.php
. Combined with your CORE_PATH
, it results in C:\wamp\www\smart-rebate-web\coreunctions\common.php
.
Tip: Use double-quotes strings only when you are sure you need them - interpolating variables, special sequences, SQL code, etc. They can ruin your day if you miss something unwanted in them. Also, when dealing with system paths, it's best to use DIRECTORY_SEPARATOR
instead of /
or \
. This way you can easily migrate from one platform to another without having to refactor your code.
Cheers.
Upvotes: 2