Escolar Documentos
Profissional Documentos
Cultura Documentos
http://php.net/manual/es/language.namespaces.r...
Downloads
Documentation
Get Involved
Help
Search
PHPKonf: Istanbul PHP Conference 2017
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
Handling file uploads
Using remote files
1 de 7
17/01/17 16:33
http://php.net/manual/es/language.namespaces.r...
Connection handling
Persistent Database Connections
Safe Mode
Command line usage
Garbage Collection
DTrace Dynamic Tracing
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
Goto homepage
gs
Goto search
(current page)
/
Focus search box
2 de 7
17/01/17 16:33
http://php.net/manual/es/language.namespaces.r...
3 de 7
17/01/17 16:33
http://php.net/manual/es/language.namespaces.r...
$d=namespace\MICONSTANTE;//vaselaseccin"Eloperadornamespacey
//laconstante__NAMESPACE__"
$d=__NAMESPACE__.'\MICONSTANTE';
echoconstant($d);//vaselaseccin"Espaciosdenombresycaractersticasdinmicasdellenguaje"
?>
Nota:
Los nombres de los espacios de nombres PHP y php, y los nombres
compuestos a partir de estos (como PHP\Classes) estn reservados para el uso
interno del lenguaje y no deben utilizarse en el cdigo del espacio del usuario.
add a note
up
down
151
Dmitry Snytkine
5 years ago
Just a note: namespace (even nested or sub-namespace) cannot be just a number, it must start with a
letter.
For example, lets say you want to use namespace for versioning of your packages or versioning of
your API:
namespace Mynamespace\1; // Illegal
Instead use this:
namespace Mynamespace\v1; // OK
up
down
64
pierstoval at gmail dot com
2 years ago
To people coming here by searching about namespaces, know that a consortium has studied about best
practices in PHP, in order to allow developers to have common coding standards.
These best practices are called "PHP Standard Recommendations" , also known as PSR.
4 de 7
17/01/17 16:33
http://php.net/manual/es/language.namespaces.r...
5 de 7
17/01/17 16:33
http://php.net/manual/es/language.namespaces.r...
} else {
echo 'Class "'.$className.'" does not exist.';
}
}
spl_autoload_register('loadClass'); // Registers the autoloader
?>
A standardized autoloader will get the class you want to instanciate (MyTool) and get the FQCN,
transform it into a file path, and check if the file exists. If it does, it will <?php include(); ?>
it, and if you wrote your class correctly, the class will be available within its correct namespace.
Then, if you have the following code :
<?php $tool = new Pierstoval/Tools/MyTool(); ?>
The autoloader will transform the FQCN into this path :
{path}/src/Pierstoval/Tools/MyTool.php
This might be the best practices ever in PHP framework developments, such as Symfony or others.
up
down
33
php dot net at e-z dot name
3 years ago
php namespaces are case-insensitive:
file1.php:
<?php
namespace foo;
function bar()
{
echo 'from bar';
}
?>
file2.php:
<?php
fOo\bar() // output: from bar
?>
up
down
-1
sonkengmaldini at gmail dot com
1 year ago
add a note
Espacios de nombres
Resumen de los espacios de nombres
Definir espacios de nombres
Declarar subespacios de nombres
6 de 7
17/01/17 16:33
http://php.net/manual/es/language.namespaces.r...
7 de 7
17/01/17 16:33