Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
function in class, run only if variable is not set, PHP

I want to write function in class. I want to run this function only if one variable is not set. I have 3 thoughts about this, but I do not know which one is best and looks "more professional".

1:

if (!isset($this->variable) {
     $this->functionXxx();
}

2:

private function functionXxx()
{
     if (!isset($this->variable)) {
         //code here
     } 
}

3:

private function functionXxx()
{
     if (isset($this->variable)) {
         return;
     } 
     //code here
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

First of all you should stop call methods function.

Second, if methodXxx returns something after operation you can use 3rd option, but if methodXxx is what we call void function (returns nothing) than you should use 2nd option.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda