downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Output Control> <Funciones de sobrecarga de objetos
Last updated: Fri, 20 May 2011

view this page in

overload

(PHP 4 >= 4.3.0)

overloadHabilita la sobrecarga de una propiedad y una llamda a un método de una clase

Descripción

void overload ( string $class_name )

La función overload() habiltará la sobrecarga de una propiedad y una llamada a un método de una clase identificada mediante class_name.

Parámetros

class_name

El nombre de la clase sobrecargada, como cadena

Valores devueltos

No devuelve ningún valor.

Ejemplos

Vea un ejemplo en la sección de introducción de esta parte.



add a note add a note User Contributed Notes overload
osminosm at gmail dot com 22-Jan-2009 03:22
creating two methods with the same name won't work for sure (maybe in next versions i hope)
but for now all i could come up with something that looks like overloaded functions from the outside but still makes it a bit difficult for the one who's coding the actual class
as we can see in the code bellow i've used a default value for the $name argument, so when the Test() method is called with no arguments the $name argument is by default passed as NULL (or any value you wanna pass)
<?php

class Test
 
{
  function
Test($name=NULL)
    {
    echo
'Hello, ';
    if(
$name)
      {
      echo
$name.'<br>';
      }
    else
      {
      echo
'stranger<br>';
      }
    }
  }
 
$t1=new Test();                            // Output : Hello, stranger
$t2=new Test('Osman Kalache');     // Output : Hello, Osman Kalache

?>

the bad side of this trick is that you have to test your arguments (imagine how many IFs and ELSEs you get if you had just 5 arguments)
but still makes your classes easy to use.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites