Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

292
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!