1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[Whats make this error] PHP Notice: Use of undefined constant

Discussion in 'PHP' started by basketmen, Apr 10, 2015.

  1. #1
    I just moved to new host
    In this new host i always got error_log, even with this simple php file :
    <?php define(Y,120); ?>
    PHP:
    this is the error_log content:

    i can add single quote wrapping the Y like this to fix it
    <?php define('Y',120); ?>
    PHP:
    but there are a lot of code like that, it is better if i dont need to change the files,
    but just change the hosting required, what is it actually? is it because using litespeed?

    in old hosting there is cgi-fcgi information
    [​IMG]

    in new hosting is using litespeed
    [​IMG]
     
    basketmen, Apr 10, 2015 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    The issue, what is happening is you are trying to use the constant Y which doesn't exist, so PHP converts it to a string for you. Take this for example:

    
    <?php
    define('Y', 'TEST');
    define(Y, 'new');
    
    echo TEST; // will give you new
    echo Y; // will give you TEST
    
    PHP:
    What is happening is that the constant Y exists (unlike in your code) causing the creation of a new constant with the value of the Y constant (TEST).

    It is not really an issue per say -you can let PHP convert those for you, but it would be best to update the code. You can create a PHP script to replace the code for you, or if you have Command Prompt access you can run a SED command to do the replaces for you.
     
    ThePHPMaster, Apr 10, 2015 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Not to mention that it's just lazy coding - and bad practice. That you've not been aware of this before means that you haven't had "show errors" on while developing, which isn't really smart either - I suggest fixing your code, that is always the best practice. I don't know what you're using DEFINE for, but usually it's not something you use for anything important - personally, I use it for translations (I define a variable with different content based on language) - and that can be easily done via a loop and arrays.
     
    PoPSiCLe, Apr 11, 2015 IP