PHP Constants - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

PHP Constants

Description:

naming rules: like any label in PHP (same as what follows the $ sign in variables) ... __FUNCTION__ function name __CLASS__ class name __METHOD__ method name ... – PowerPoint PPT presentation

Number of Views:200
Avg rating:3.0/5.0
Slides: 6
Provided by: capi7
Category:
Tags: php | constants | method

less

Transcript and Presenter's Notes

Title: PHP Constants


1
PHP - Constants
  • Case sensitive
  • Convention upper case
  • naming rules like any label in PHP (same as
    what follows the sign in variables)
  • You can define a constant by using the define( )
    function.
  • Once a constant is defined, it can never be
    changed or undefined.

2
PHP - Constants
  • Constants do not have a dollar sign () before
    them
  • Constants may only be defined using the define( )
    function, not by simple assignment
  • Constants may be defined and accessed anywhere
    without regard to variable scoping rules
  • Constants may not be redefined or undefined once
    they have been set and
  • Constants may only evaluate to scalar values.

3
PHP - Constants
  • lt?php define("CONSTANT", "Hello world.")
    echo CONSTANT // ? "Hello world."?gt

4
PHP Magic Constants
  • There are five magical constants that change
    depending on where they are used.
  • For example, the value of __LINE__ depends on the
    line that it's used on in your script
  • These special constants are case-insensitive

5
PHP Magic Constants
  • __LINE__ ? current line number
  • __FILE__ ? full path and file name
  • __FUNCTION__ ? function name
  • __CLASS__ ? class name
  • __METHOD__ ? method name
Write a Comment
User Comments (0)
About PowerShow.com