PHP Interview questions


Total available count: 33
Subject - PHP Frameworks
Subsubject - PHP

What are Magic constants?

PHP provides a huge number of predefined constants to any script which it runs. Many of these constants are created by various extensions and will only be present when those extensions are available, either via dynamic loading or due to they have been compiled in.

There are 8 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. The below special constants are not case sensitive.

A few "magical" PHP constants:

Name

Description

LINE

The current line number of the file.

FILE

The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.

DIR

The directory of the file. If used inside the include, the directory of the included file is returned. This is equivalent to dirname(FILE). This directory name does not have a trailing slash unless it is the root directory.

FUNCTION

The function name.

CLASS

The class name. The class name includes the namespace it was declared in (e.g. Foo\Bar). Note that as of PHP 5.4, CLASS works also in traits. When used in a trait method, CLASS is the name of the class the trait is used in.

TRAIT

The trait name. The trait name includes the namespace it was declared in (e.g. Foo\Bar).

METHOD

The class method name.

NAMESPACE

The name of the current namespace.




Next 5 interview question(s)

1
How to define constants?
2
What is need for using static variables?
3
What is the difference between global vs $GLOBALS?
4
What is Void?
5
What is the difference between gettype() vs str replace?