Parámetros de la función de PHP

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Enero 30th, 2010, 6:02 pm

Ive estado trabajando en un problema de toda la tarde, y yo no podía entender lo que estaba pasando. Mis resultados de la consulta se devuelve siempre la primera columna de las tablas y nada más. Finalmente descided a mirar a la clase de base de datos que se estaba utilizando y se encontró una interesante porción de código.

PHP Código: [ Select ]
/**
    * Not sure why this is here either.
    *
    * @param string $query
    * @param boolean $cache Use Memcache
    * @param int $ttl Memcached's expiration time in seconds
    */
    public function customQuery ( $query , $cache = false , $ttl = 300 )
    {
        return $this -> query ( $query , $cache , $ttl );
    }
///
 
 /**
    * Queries the database for a mysql result set link or the processed result set.
    *
    * @param string $query The query to execute
    * @param string $method The method to fetch the result set link with
    * @param boolean $multiple If there are multiple rows to be fetched
    * @param boolean $cache Use Memcache
    * @param int $ttl Memcached's expiration time in seconds
    *
    * @return mixed The mysql result set link or the processed result set, depending on weather or not $method was passed.
    */
    public function query ( $query , $method = false , $multiple = false , $cache = false , $ttl = 300 )
    {
         /// Trimmed
}
 
  1. /**
  2.     * Not sure why this is here either.
  3.     *
  4.     * @param string $query
  5.     * @param boolean $cache Use Memcache
  6.     * @param int $ttl Memcached's expiration time in seconds
  7.     */
  8.     public function customQuery ( $query , $cache = false , $ttl = 300 )
  9.     {
  10.         return $this -> query ( $query , $cache , $ttl );
  11.     }
  12. ///
  13.  
  14.  /**
  15.     * Queries the database for a mysql result set link or the processed result set.
  16.     *
  17.     * @param string $query The query to execute
  18.     * @param string $method The method to fetch the result set link with
  19.     * @param boolean $multiple If there are multiple rows to be fetched
  20.     * @param boolean $cache Use Memcache
  21.     * @param int $ttl Memcached's expiration time in seconds
  22.     *
  23.     * @return mixed The mysql result set link or the processed result set, depending on weather or not $method was passed.
  24.     */
  25.     public function query ( $query , $method = false , $multiple = false , $cache = false , $ttl = 300 )
  26.     {
  27.          /// Trimmed
  28. }
  29.  


Por lo que yo sé que usted no puede hacer esto en PHP. No importa qué nombre le das una variable, los parámetros se asignan siempre en orden. Estoy en lo correcto en este o me he estado perdiendo algo de todos estos años.
#define NULL (::rand() % 2)
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Enero 30th, 2010, 6:02 pm

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Registrado: Feb 10, 2004
  • Mensajes: 13458
  • Loc: Florida
  • Status: Offline

Nota Enero 30th, 2010, 6:23 pm

Thats la manera Siempre he entendido.

PHP Código: [ Select ]
<?php
 
class test
{
        function second($one = 1, $three = 3, $five = 5)
        {
                $this->first($one, $three, $five);
        }
 
        function first($one = 1, $two = 2, $three = 3, $four = 4, $five = 5)
        {
                echo "\n" . print_r(func_get_args(), true) . "\n";
        }
}
 
$obj = new test();
$obj->second();
 
?>
  1. <?php
  2.  
  3. class test
  4. {
  5.         function second($one = 1, $three = 3, $five = 5)
  6.         {
  7.                 $this->first($one, $three, $five);
  8.         }
  9.  
  10.         function first($one = 1, $two = 2, $three = 3, $four = 4, $five = 5)
  11.         {
  12.                 echo "\n" . print_r(func_get_args(), true) . "\n";
  13.         }
  14. }
  15.  
  16. $obj = new test();
  17. $obj->second();
  18.  
  19. ?>


Código: [ Select ]
Array
(
  [0] => 1
  [1] => 3
  [2] => 5
)
  1. Array
  2. (
  3.   [0] => 1
  4.   [1] => 3
  5.   [2] => 5
  6. )
Strong with this one, the sudo is.
  • spork
  • Brewmaster
  • Silver Member
  • Avatar de Usuario
  • Registrado: Sep 22, 2003
  • Mensajes: 6134
  • Loc: Seattle, WA
  • Status: Offline

Nota Enero 31st, 2010, 2:54 pm

Im no seguro de entender lo que están pidiendo aquí :scratchhead:
The Beer Monocle. Classy.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • Avatar de Usuario
  • Registrado: May 22, 2004
  • Mensajes: 3415
  • Loc: Richland, WA
  • Status: Offline

Nota Enero 31st, 2010, 3:04 pm

Los argumentos de palabra clave como en Python. Aviso Youll en el código anterior que el $ TTL 300 se asigna a $ múltiples.
#define NULL (::rand() % 2)
  • spork
  • Brewmaster
  • Silver Member
  • Avatar de Usuario
  • Registrado: Sep 22, 2003
  • Mensajes: 6134
  • Loc: Seattle, WA
  • Status: Offline

Nota Enero 31st, 2010, 8:31 pm

Ellos son asignados por el orden, no el nombre.
The Beer Monocle. Classy.
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Registrado: Feb 10, 2004
  • Mensajes: 13458
  • Loc: Florida
  • Status: Offline

Nota Enero 31st, 2010, 8:48 pm

Sería bueno si pudiera espacio de nombres de argumentos pasados, algo como esto.

Código: [ Select ]
function method($one = 1, $two = 2) {}

method(two:"alternate value");
  1. function method($one = 1, $two = 2) {}
  2. method(two:"alternate value");


Después $ se podría usar el valor por defecto.
Strong with this one, the sudo is.
  • spork
  • Brewmaster
  • Silver Member
  • Avatar de Usuario
  • Registrado: Sep 22, 2003
  • Mensajes: 6134
  • Loc: Seattle, WA
  • Status: Offline

Nota Enero 31st, 2010, 9:46 pm

Permítame presentarle a los dos.

Python, Jobert . Jobert, Python . Improvisador jugar malos con PHP, mientras que ustedes conozcan unos a otros.
The Beer Monocle. Classy.

Publicar Información

  • Total de mensajes en este tema: 7 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 166 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC