You are on page 1of 10

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

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

1 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

HTTP authentication with PHP


Cookies
Sessions
Dealing with XForms
Handling file uploads
Using remote files
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

2 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

Next man page


G
Scroll to bottom
gg
Scroll to top
gh
Goto homepage
gs
Goto search
(current page)
/
Focus search box
Tipos
Separacin de instrucciones
Manual de PHP
Referencia del lenguaje
Sintaxis bsica
Change language:

Spanish

Edit Report a Bug

Comentarios
PHP admite comentarios al estilo de 'C', 'C++' y de consola de Unix (estilo de
Perl). Por ejemplo:
<?php
echo'Estoesunaprueba';//Estoesuncomentarioalestilodec++deunasolalnea
/*Estoesuncomentariomultilnea
yotralnadecomentarios*/
echo'Estoesotraprueba';
echo'Unapruebafinal';#Estoesuncomentarioalestilodeconsoladeunasolalnea
?>

Los comentarios al estilo de "una sola lnea" solo comentan hasta el final de la
lnea o del bloque actual de cdigo de PHP, lo primero que suceda. Esto implica
que el cdigo HTML despus de // ... ?> o # ... ?> SER impreso: ?> sale del
modo PHP y vuelve al modo HTML, por lo que // o # no pueden influir en eso.
Si la directiva de configuracin asp_tags est activada, acta igual que // %> y
# %>. Sin embargo, la etiqueta </script> no sale del modo PHP en un
comentario de una sola lnea.
<h1>Estoesun<?php#echo'simple';?>ejemplo</h1>
<p>Elencabezadoanteriordir'Estoesunejemplo'.</p>

Los comentarios al estilo de 'C' finalizan con el primer */ que se encuentre.


Asegrese de no anidar comentarios al estilo de 'C'. Es muy fcil cometer este
error cuando se intenta comentar un bloque grande de cdigo.
3 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

<?php
/*
echo'Estoesunaprueba';/*Estecomentariocausarunproblema*/
*/
?>

add a note

User Contributed Notes 13 notes


up
down
177
J. Prettyman
2 years ago
Notes can come in all sorts of shapes and sizes. They vary, and their uses are completely
up to the person writing the code. However, I try to keep things consistent in my code
that way it's easy for the next person to read. So something like this might help...
<?php
//======================================================================
// CATEGORY LARGE FONT
//======================================================================
//----------------------------------------------------// Sub-Category Smaller Font
//----------------------------------------------------/* Title Here Notice the First Letters are Capitalized */
# Option 1
# Option 2
# Option 3
/*
* This is a detailed explanation
* of something that should require
* several paragraphs of information.
*/
// This is a single line quote.
?>

up
down
192
M Spreij
11 years ago
A nice way to toggle the commenting of blocks of code can be done by mixing the two
comment styles:
<?php
//*

4 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

if ($foo) {
echo $bar;
}
// */
sort($morecode);
?>
Now by taking out one / on the first line..
<?php
/*
if ($foo) {
echo $bar;
}
// */
sort($morecode);
?>
..the block is suddenly commented out.
This works because a /* .. */ overrides //. You can even "flip" two blocks, like this:
<?php
//*
if ($foo) {
echo $bar;
}
/*/
if ($bar) {
echo $foo;
}
// */
?>
vs
<?php
/*
if ($foo) {
echo $bar;
}
/*/
if ($bar) {
echo $foo;
}
// */
?>

up
down
72
magnesium dot oxide dot play+php at gmail dot com
3 years ago
It is worth mentioning that, HTML comments have no meaning in PHP parser. So,
<!-- comment
<?php echo some_function(); ?>
-->

5 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

WILL execute some_function() and echo result inside HTML comment.

up
down
48
hcderaad at wanadoo dot nl
11 years ago
Comments in PHP can be used for several purposes, a very interesting one being that you
can generate API documentation directly from them by using PHPDocumentor
(http://www.phpdoc.org/).
Therefor one has to use a JavaDoc-like comment syntax (conforms to the DocBook DTD),
example:
<?php
/**
* The second * here opens the DocBook commentblock, which could later on<br>
* in your development cycle save you a lot of time by preventing you having to rewrite<br>
* major documentation parts to generate some usable form of documentation.
*/
?>
Some basic html-like formatting is supported with this (ie <br> tags) to create something
of a layout.

up
down
42
Steve
12 years ago
Be careful when commenting out regular expressions.
E.g. the following causes a parser error.
I do prefer using # as regexp delimiter anyway so it won't hurt me ;-)
<?php
/*
$f->setPattern('/^\d.*/');
*/
?>

up
down
30
J Lee
10 years ago
MSpreij (8-May-2005) says /* .. */ overrides //
Anonymous (26-Jan-2006) says // overrides /* .. */
Actually, both are correct. Once a comment is opened, *everything* is ignored until the
end of the comment (or the end of the php block) is reached.

6 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

Thus, if a comment is opened with:


// then /* and */ are "overridden" until after end-of-line
/* then // is "overridden" until after */

up
down
20
jballard at natoga dot com
6 years ago
Comments do NOT take up processing power.
So, for all the people who argue that comments are undesired because they take up
processing power now have no reason to comment ;)
<?php
// Control
echo microtime(), "<br />"; // 0.25163600 1292450508
echo microtime(), "<br />"; // 0.25186000 1292450508
// Test
echo microtime(), "<br />"; // 0.25189700 1292450508
# TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
TEST TEST
# .. Above comment repeated 18809 times ..
echo microtime(), "<br />"; // 0.25192100 1292450508
?>
They take up about the same amount of time (about meaning on a repeated testing, sometimes
the difference between the control and the test was negative and sometimes positive).

up
down
21
theblazingangel at aol dot com
9 years ago
it's perhaps not obvious to some, but the following code will cause a parse error! the ?>
in //?> is not treated as commented text, this is a result of having to handle code on one
line such as <?php echo 'something'; //comment ?>
<?php
if(1==1)
{
//?>
}
?>
i discovered this "anomally" when i commented out a line of code containing a regex which
itself contained ?>, with the // style comment.
e.g. //preg_match('/^(?>c|b)at$/', 'cat', $matches);
will cause an error while commented! using /**/ style comments provides a solution. i
don't know about # style comments, i don't ever personally use them.

7 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

up
down
16
fun at nybbles dot com
10 years ago
a trick I have used in all languages to temporarily block out large sections (usually for
test/debug/new-feature purposes), is to set (or define) a var at the top, and use that to
conditionally comment the blocks; an added benefit over if(0) (samuli's comment from
nov'05) is that u can have several versions or tests running at once, and u dont require
cleanup later if u want to keep the blocks in: just reset the var.
personally, I use this more to conditionally include code for new feature testing, than to
block it out,,,, but hey, to each their own :)
this is also the only safe way I know of to easily nest comments in any language, and
great for multi-file use, if the conditional variables are placed in an include :)
for example, placed at top of file:
<?php $ver3 = TRUE;
$debug2 = FALSE;
?>
and then deeper inside the file:
<?php if ($ver3) {
print("This code is included since we are testing version 3");
}
?>
<?php if ($debug2) {
print("This code is 'commented' out");
}
?>

up
down
3
Wolfsbay at ya dot ru
6 years ago
If you are using editor with code highlight, its much easier to notice error like /* */
*/.

up
down
-6
Anonymous
3 years ago

up
down
8 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

-10
team at researchbib dot com
5 years ago

up
down
-13
Anonymous
10 years ago

add a note

Sintaxis bsica
Etiquetas de PHP
Salir de HTML
Separacin de instrucciones
Comentarios

9 de 10

14/01/17 10:45

PHP: Comentarios - Manual

http://php.net/manual/es/language.basic-syntax...

Copyright 2001-2017 The PHP Group


My PHP.net
Contact
Other PHP.net sites
Mirror sites
Privacy policy

10 de 10

14/01/17 10:45

You might also like