SlideShare una empresa de Scribd logo
1 de 8
Javier Orozco Peñaranda
Desarrollo Web con PHP
7 RAZONES PARA EL USO DE FUNCIONES EN PHP
1. MENOS ESCRITURA
Solo se requiere escribir las instrucciones una
sola vez dentro de la función. Cuando se
requieran solo basta con llamar la función.
/* Llamado a la Función con los 3 parametros */
$total = operaciones($num1,$num2,$opera);
echo "EL RESULTADO DE LA RESTA ES :".$total;
2. FACIL ACTUALIZACION
De requerirse un cambio en el código, al realizar
este cambio en la función automáticamente se
modifica todas las instancias del programa
donde se están invocando.
function operaciones ($n1,$n2){
$tot=$n1+$n2;
return $tot;
}
}
function operaciones ($n1,$n2){
$tot=$n1*$n2;
return $tot;
}
}
3. FACIL LECTURA
Es mucho mas fácil entender el nombre y lo que
realiza una función, que un gran conjunto de
operaciones.
$tot=$n1+$n2;
echo $tot;
$tot=$n1*$n2;
echo $tot;
$tot=$n1-$n2;
echo $tot;
$tot=$n1+$n2;
echo $tot;
/* Llamado a la Función con los 3 parametros */
$total = operaciones($num1,$num2,$opera);
echo "EL RESULTADO DE LA RESTA ES :".$total;
4. MENOS ERRORES
Si se hallan errores después de haber escrito la
función y estos se corrigen, esta funcionara
correctamente cada vez que la usemos.
function operaciones ($n1,$n2){
$tot=$n1+$n2;
returrn $total;
}
} function operaciones ($n1,$n2){
$tot=$n1+$n2;
return $tot;
}
}
5. FIABILIDAD
Es mas confiable un modulo que se ha creado y
que funciona correctamente a uno que se va a
crear desde cero y sin probar.
function suma ($n1,$n2){
$tot=$n1+$n2;
returrn $total;
}
}
function multiplica ($n1,$n2){
$tot=$n1*$n2;
return $tot;
}
}
6. REUTILIZABLE
Se puede crear una biblioteca de funciones con
el fin de que estos códigos se puedan utilizar
nuevamente en alguna instancia del programa
llamando al archivo.
<?php
require_once './biblioteca.php';
$num1=12;
$num2=3;
$opera="R";
/* Llamado a la Función con los 3 parametros */
$total = operaciones($num1,$num2,$opera);
echo "EL RESULTADO DE LA RESTA ES :".$total;
?>
7. COMPROBACION INDIVIDUAL
Se puede probar solamente el código de la
función, sin necesidad de hacerlo con todo el
archivo. <?php
function suma ($n1,$n2){
$tot=$n1+$n2;
return $tot;
}
$num1=12;
$num2=3;
$total = operaciones($num1,$num2,$opera);
echo "EL RESULTADO DE LA SUMA ES :".$total;
?>

Más contenido relacionado

La actualidad más candente

Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Edureka!
 
Formation PHP
Formation PHPFormation PHP
Formation PHPkemenaran
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners PerlDave Cross
 
Haskell study 12
Haskell study 12Haskell study 12
Haskell study 12Nam Hyeonuk
 
Examen principal- php - correction
Examen principal- php - correctionExamen principal- php - correction
Examen principal- php - correctionInes Ouaz
 
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive gridRoel Hartman
 
Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5Kristen Le Liboux
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesCiaranMcNulty
 
Sous-Interrogations - sql oracle
Sous-Interrogations - sql oracleSous-Interrogations - sql oracle
Sous-Interrogations - sql oraclewebreaker
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)Win Yu
 

La actualidad más candente (20)

Day02 a pi.
Day02   a pi.Day02   a pi.
Day02 a pi.
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 
Formation PHP
Formation PHPFormation PHP
Formation PHP
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Haskell study 12
Haskell study 12Haskell study 12
Haskell study 12
 
Clean code
Clean codeClean code
Clean code
 
Chapitre 4 Java script
Chapitre 4 Java scriptChapitre 4 Java script
Chapitre 4 Java script
 
Examen principal- php - correction
Examen principal- php - correctionExamen principal- php - correction
Examen principal- php - correction
 
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive grid
 
Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5Programmation orientée objet en PHP 5
Programmation orientée objet en PHP 5
 
Programa de Pila Estática
Programa de Pila EstáticaPrograma de Pila Estática
Programa de Pila Estática
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Practical Celery
Practical CeleryPractical Celery
Practical Celery
 
Sous-Interrogations - sql oracle
Sous-Interrogations - sql oracleSous-Interrogations - sql oracle
Sous-Interrogations - sql oracle
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
Método de la bisección
Método de la bisecciónMétodo de la bisección
Método de la bisección
 

Similar a 7 razones usar funciones PHP

Similar a 7 razones usar funciones PHP (20)

Desarrollo web con php
Desarrollo web con phpDesarrollo web con php
Desarrollo web con php
 
Jose manuel avila gonzález
Jose manuel avila gonzálezJose manuel avila gonzález
Jose manuel avila gonzález
 
Jose manuel avila gonzález
Jose manuel avila gonzálezJose manuel avila gonzález
Jose manuel avila gonzález
 
FUNCIONES EN PHP
FUNCIONES EN PHPFUNCIONES EN PHP
FUNCIONES EN PHP
 
7 Razones para usar las funciones php
7 Razones para usar las funciones php7 Razones para usar las funciones php
7 Razones para usar las funciones php
 
Funciones y procedimientos
Funciones y procedimientosFunciones y procedimientos
Funciones y procedimientos
 
Funciones
FuncionesFunciones
Funciones
 
Funciones en C
Funciones en CFunciones en C
Funciones en C
 
Funciones
FuncionesFunciones
Funciones
 
Ventaja del uso de las Funciones en PHP
Ventaja del uso de las Funciones en PHPVentaja del uso de las Funciones en PHP
Ventaja del uso de las Funciones en PHP
 
Razones para el uso de funciones en php
Razones para el uso de funciones en phpRazones para el uso de funciones en php
Razones para el uso de funciones en php
 
Metodos funciones
Metodos funcionesMetodos funciones
Metodos funciones
 
Sesion virtual funciones_php_actividad3_
Sesion virtual funciones_php_actividad3_Sesion virtual funciones_php_actividad3_
Sesion virtual funciones_php_actividad3_
 
Desarrollo web con php unidad 3
Desarrollo web con php unidad 3Desarrollo web con php unidad 3
Desarrollo web con php unidad 3
 
P_UNIDAD 4 FUNCIONES.pptx
P_UNIDAD 4 FUNCIONES.pptxP_UNIDAD 4 FUNCIONES.pptx
P_UNIDAD 4 FUNCIONES.pptx
 
I6 u2
I6 u2I6 u2
I6 u2
 
Funciones
FuncionesFunciones
Funciones
 
Desarrollo web con php
Desarrollo web con phpDesarrollo web con php
Desarrollo web con php
 
Ventajas de usar funciones en php
Ventajas de usar funciones en phpVentajas de usar funciones en php
Ventajas de usar funciones en php
 
Funcionesclase1
Funcionesclase1Funcionesclase1
Funcionesclase1
 

7 razones usar funciones PHP

  • 1. Javier Orozco Peñaranda Desarrollo Web con PHP 7 RAZONES PARA EL USO DE FUNCIONES EN PHP
  • 2. 1. MENOS ESCRITURA Solo se requiere escribir las instrucciones una sola vez dentro de la función. Cuando se requieran solo basta con llamar la función. /* Llamado a la Función con los 3 parametros */ $total = operaciones($num1,$num2,$opera); echo "EL RESULTADO DE LA RESTA ES :".$total;
  • 3. 2. FACIL ACTUALIZACION De requerirse un cambio en el código, al realizar este cambio en la función automáticamente se modifica todas las instancias del programa donde se están invocando. function operaciones ($n1,$n2){ $tot=$n1+$n2; return $tot; } } function operaciones ($n1,$n2){ $tot=$n1*$n2; return $tot; } }
  • 4. 3. FACIL LECTURA Es mucho mas fácil entender el nombre y lo que realiza una función, que un gran conjunto de operaciones. $tot=$n1+$n2; echo $tot; $tot=$n1*$n2; echo $tot; $tot=$n1-$n2; echo $tot; $tot=$n1+$n2; echo $tot; /* Llamado a la Función con los 3 parametros */ $total = operaciones($num1,$num2,$opera); echo "EL RESULTADO DE LA RESTA ES :".$total;
  • 5. 4. MENOS ERRORES Si se hallan errores después de haber escrito la función y estos se corrigen, esta funcionara correctamente cada vez que la usemos. function operaciones ($n1,$n2){ $tot=$n1+$n2; returrn $total; } } function operaciones ($n1,$n2){ $tot=$n1+$n2; return $tot; } }
  • 6. 5. FIABILIDAD Es mas confiable un modulo que se ha creado y que funciona correctamente a uno que se va a crear desde cero y sin probar. function suma ($n1,$n2){ $tot=$n1+$n2; returrn $total; } } function multiplica ($n1,$n2){ $tot=$n1*$n2; return $tot; } }
  • 7. 6. REUTILIZABLE Se puede crear una biblioteca de funciones con el fin de que estos códigos se puedan utilizar nuevamente en alguna instancia del programa llamando al archivo. <?php require_once './biblioteca.php'; $num1=12; $num2=3; $opera="R"; /* Llamado a la Función con los 3 parametros */ $total = operaciones($num1,$num2,$opera); echo "EL RESULTADO DE LA RESTA ES :".$total; ?>
  • 8. 7. COMPROBACION INDIVIDUAL Se puede probar solamente el código de la función, sin necesidad de hacerlo con todo el archivo. <?php function suma ($n1,$n2){ $tot=$n1+$n2; return $tot; } $num1=12; $num2=3; $total = operaciones($num1,$num2,$opera); echo "EL RESULTADO DE LA SUMA ES :".$total; ?>