Professional Documents
Culture Documents
Downloads
Documentation
Get Involved
Help
Search
Getting Started
Introduction
A simple tutorial
Language Reference
Basic syntax
Types
Variables
Constants
Expressions
Operators
Control Structures
Functions
Classes and Objects
Namespaces
Errors
Exceptions
Generators
References Explained
Predefined Variables
Predefined Exceptions
Predefined Interfaces and Classes
Context options and parameters
Supported Protocols and Wrappers
Security
Introduction
General considerations
Installed as CGI binary
Installed as an Apache module
Session Security
Filesystem Security
Database Security
Error Reporting
Using Register Globals
User Submitted Data
Magic Quotes
Hiding PHP
Keeping Current
Features
HTTP authentication with PHP
Cookies
Sessions
Dealing with XForms
http://php.net/manual/es/language.constants.predefined.php 1/8
11/9/2017 PHP: Constantes predefinidas - Manual
Function Reference
Affecting PHP's Behaviour
Audio Formats Manipulation
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Credit Card Processing
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing
Variable and Type Related Extensions
Web Services
Windows Only Extensions
XML Manipulation
GUI Extensions
Keyboard Shortcuts
?
This help
j
Next menu item
k
Previous menu item
gp
Previous man page
gn
Next man page
G
Scroll to bottom
gg
Scroll to top
gh
http://php.net/manual/es/language.constants.predefined.php 2/8
11/9/2017 PHP: Constantes predefinidas - Manual
Goto homepage
gs
Goto search
(current page)
/
Focus search box
Expresiones »
« Sintaxis
Manual de PHP
Referencia del lenguaje
Constantes
Constantes predefinidas ¶
PHP ofrece un gran número de constantes predefinidas a cualquier script en ejecucción. Muchas de estas
constantes, sin embargo, son creadas por diferentes extensiones, y sólo estarán presentes si dichas extensiones
están disponibles, bien por carga dinámica o porque han sido compiladas.
Hay nueve constantes mágicas que cambian dependiendo de dónde se emplean. Por ejemplo, el valor de
__LINE__ depende de la línea en que se use en el script. Todas estas constantes «mágicas» se resuelven durante la
compilación, a diferencia de las constantes normales que lo hacen durante la ejecución. Estas constantes
especiales son sensibles a mayúsculas Estas constantes especiales distinguen mayúsculas y minúsculas, y son las
siguientes:
http://php.net/manual/es/language.constants.predefined.php 3/8
11/9/2017 PHP: Constantes predefinidas - Manual
Historial de cambios ¶
Versión Descripción
5.5.0 Se añadió la constante mágica ::class
5.4.0 Se añadió la constante __TRAIT__
5.3.0 Se añadieron las constantes __DIR__ y __NAMESPACE__
5.0.0 Se añadió la constante __METHOD__
Antes de esta versión, los valores de algunas constantes mágicas estaban siempre en minúsculas.
5.0.0
Ahora todas ellas están en mayúsculas (contienen nombres mientras eran declaradas).
4.3.0 Se añadieron las constantes __FUNCTION__ y __CLASS__
__FILE__ siempre contiene una ruta absoluta con enlaces simbólicos resueltos, mientras que en
4.0.2
versiones antiguas contenía una ruta relativa bajo algunas circunstancias
add a note
up
down
180
vijaykoul_007 at rediffmail dot com ¶
11 years ago
the difference between
__FUNCTION__ and __METHOD__ as in PHP 5.0.4 is that
while as __METHOD__ returns the name of the class alongwith the name of the function
class trick
{
function doit()
{
echo __FUNCTION__;
}
function doitagain()
{
echo __METHOD__;
}
}
$obj=new trick();
$obj->doit();
output will be ---- doit
$obj->doitagain();
output will be ----- trick::doitagain
up
down
12
Sbastien Fauvel ¶
1 year ago
Note a small inconsistency when using __CLASS__ and __METHOD__ in traits (stand php 7.0.4): While
__CLASS__ is working as advertized and returns dynamically the name of the class the trait is being
http://php.net/manual/es/language.constants.predefined.php 4/8
11/9/2017 PHP: Constantes predefinidas - Manual
used in, __METHOD__ will actually prepend the trait name instead of the class name!
up
down
7
php at kenman dot net ¶
3 years ago
Just learned an interesting tidbit regarding __FILE__ and the newer __DIR__ with respect to code run
from a network share: the constants will return the *share* path when executed from the context of
the share.
Examples:
// normal context
// called as "php -f c:\test.php"
__DIR__ === 'c:\';
__FILE__ === 'c:\test.php';
NOTE: realpath('.') always seems to return an actual filesystem path regardless of the execution
context.
up
down
14
Tomek Perlak [tomekperlak at tlen pl] ¶
10 years ago
The __CLASS__ magic constant nicely complements the get_class() function.
<?php
class base_class
{
function say_a()
{
echo "'a' - said the " . __CLASS__ . "<br/>";
}
function say_b()
{
echo "'b' - said the " . get_class($this) . "<br/>";
}
http://php.net/manual/es/language.constants.predefined.php 5/8
11/9/2017 PHP: Constantes predefinidas - Manual
{
function say_a()
{
parent::say_a();
echo "'a' - said the " . __CLASS__ . "<br/>";
}
function say_b()
{
parent::say_b();
echo "'b' - said the " . get_class($this) . "<br/>";
}
}
$obj_b->say_a();
echo "<br/>";
$obj_b->say_b();
?>
Concluding: eye catchup at gmail dot com's note regarding whether you can or cannot define magic
constants is valid, but stating that defining __DIR__ is not useless, is not!
up
down
5
chris dot kistner at gmail dot com ¶
6 years ago
There is no way to implement a backwards compatible __DIR__ in versions prior to 5.3.0.
The only thing that you can do is to perform a recursive search and replace to dirname(__FILE__):
find . -type f -print0 | xargs -0 sed -i 's/__DIR__/dirname(__FILE__)/'
up
down
http://php.net/manual/es/language.constants.predefined.php 6/8
11/9/2017 PHP: Constantes predefinidas - Manual
1
Anonymous ¶
5 years ago
Further clarification on the __TRAIT__ magic constant.
<?php
trait PeanutButter {
function traitName() {echo __TRAIT__;}
}
trait PeanutButterAndJelly {
use PeanutButter;
}
class Test {
use PeanutButterAndJelly;
}
Here is proof:
<?php
echo (defined('__DIR__') ? '__DIR__ is defined' : '__DIR__ is NOT defined' . PHP_EOL);
echo (defined('__FILE__') ? '__FILE__ is defined' : '__FILE__ is NOT defined' . PHP_EOL);
echo (defined('PHP_VERSION') ? 'PHP_VERSION is defined' : 'PHP_VERSION is NOT defined') . PHP_EOL;
echo 'PHP Version: ' . PHP_VERSION . PHP_EOL;
?>
Output:
__DIR__ is NOT defined
__FILE__ is NOT defined
PHP_VERSION is defined
PHP Version: 5.3.6
up
down
-5
madboyka at yahoo dot com ¶
7 years ago
Since namespace were introduced, it would be nice to have a magic constant or function (like
get_class()) which would return the class name without the namespaces.
http://php.net/manual/es/language.constants.predefined.php 7/8
11/9/2017 PHP: Constantes predefinidas - Manual
Constantes
Sintaxis
Constantes predefinidas
http://php.net/manual/es/language.constants.predefined.php 8/8