Jump to content

Define Function Notice


Glese

Recommended Posts

I am trying to use absolute path across my project excluding the domain as of now and I am trying to do it as follows:

 

 

    define('root', '/php_projects/myproject/');


    // The Standard Data

    $path = "path.php";
    $connectvars = "connectvars.php";
    
    
    
    // The CSS Styles

    $reset_css = root . "view/reset.css";
    $style_css = root . "view/style.css";

 

This works so far, the only problem I am having is that it is producing a notice. And my question is, how can I get rid of the notice?

 

The notice is this one:

 

Notice: Constant root already defined in C:\xampp\htdocs\php_projects\myproject\path.php on line 3

 

Why does the notice get produced in first place? I never defined it twice, as it states. :P

Link to comment
Share on other sites

Is this path.php file being included into another file? Notices are generally human error.

 

One hack would be to check that it's not already defined before trying to define it again, but yeah, you really should know wether or not you have already defined something.

Link to comment
Share on other sites

The path.php file gets included into the header.php file, and from there on I am using variables for every path on the whole project MVC style.

 

But other than the header.php I do not include it any where. You mentioned a check, is there any specific way to do it.

 

Other than that I will try to define it directly in the header.php file and see if that will work.

 

EDIT: Putting the define function inside of header.php file did solve it, keep in mind that I did not define it twice though, I assume it may have become reloaded twice.

Link to comment
Share on other sites

keep in mind that I did not define it twice though, I assume it may have become reloaded twice.

 

Loading the definition twice *IS* defining it twice. Programming is an exact science, if you do something wrong, things break. It's doesn't matter how small the detail.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.