A consistent is a name or an identifier for a basic quality. A consistent quality can’t change amid the execution of the script. As a matter of course, a consistent is case-touchy.

To characterize a consistent you need to utilize define() function and to recover the estimation of a steady, you need to just indicating its name.
Example:-
<?php

define(“India”, 50);

echo India;

echo constant(“India”);

?>
Differences between constants and variables are:-

  • There is no compelling reason to compose a dollar sign ($) before a consistent, where as in Variable one needs to compose a dollar sign..
  • Constants might be characterized and got to anyplace without respect to variable perusing rules.
  • Once the Constants have been set, may not be reclassified or indistinct.

PHP Magic constants:-
PHP gives countless constants to any script which it runs. There are five enchanted constants that change contingent upon where they are utilized.

  1. __LINE__:- The current line number of the file.
  2. __FILE__:- The full way and filename of the record. In the event that utilized inside an incorporate, the name of the included document is returned. Subsequent to PHP 4.0.2, __FILE__ dependably contains an outright way though in more seasoned forms it contained relative way under a few circumstances.
  3. __FUNCTION__:- The capacity name. (Included PHP 4.3.0) As of PHP 5 this consistent returns the capacity name as it was pronounced (case-delicate). In PHP 4 its worth is constantly lowercased.
  4. __CLASS__:- The class name. (Included PHP 4.3.0) As of PHP 5 this consistent returns the class name as it was pronounced (case-delicate). In PHP 4 its worth is constantly lowercased.
  5. __METHOD__:- The class strategy name. (Included PHP 5.0.0) The strategy name is returned as it was pronounced (case-delicate).
Categories: PHP

0 thoughts on “PHP Constants”

Leave a Reply

Related Article

Blog

PHP Magic Methods

__get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is Read more…

Blog

WordPress Upgrade

The WordPress upgrade released time to time. We provide a WordPress upgrade, content management and maintenance services at affordable price. WordPress upgrade fixes bugs, runs cleaner, faster, and is more secure and stable. We will Read more…

Blog

Magento 2 Upload image in product

If you are trying to upload image on respective product by script then below code will help you to solve this issue. by this code you can set product thumbnail, small and large image. $objectManager Read more…