What is the difference between define() and const in PHP? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

What is the difference between define() and const in PHP?

Damian99Damian99 USAPosts: 116Member

Please explain me the main difference between define() and const.

Tagged:

Comments

  • DavidMDavidM USAPosts: 342Member

    This explains well.

  • JohnYXJohnYX CebuPosts: 3Member
    edited November 2014

    const could not be used in the global scope. You could only use this from within a class. This should be used when you want to set some kind of constant option or setting that pertains to that class. Or maybe you want to create some kind of enum.

    define can be used for the same purpose, but it can only be used in the global scope. It should only be used for global settings that affect the entire application.

  • william stevewilliam steve kakkanadPosts: 2Member

    A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script ..it could not be used in the global scope. You could only use this from within a class. This should be used when you want to set some kind of constant option or setting that pertains to that class. Or maybe you want to create some kind of enum.http://cedarsoftware.co.uk/webapplications/

    define can be used for the same purpose, but it can only be used in the global scope. It should only be used for global settings that affect the entire application.

Sign In or Register to comment.