Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:49:15+00:00 2026-06-15T03:49:15+00:00

I’m in a phase of migrating to 100% OO php and I end up

  • 0

I’m in a phase of migrating to 100% OO php and I end up with lots of questions like these. So excuse me if you find it stupid, I’m just trying to make my OO programming practices good in the start so that I don’t have to fix them later.

Is it OK to do this?

private function _some_funct($args) {
    // Some code here....
    if ($something) return;

    //Rest of code
}

Basically, there are 2 questions here.

  1. Is it OK to use return with no value after it? I use it a LOT and haven’t encoutered any drawbacks, but never saw it in somebody else’s code. I only saw return false.

  2. Is stopping functions this way OK generally or should I rethink my program’s structure?

Example of using this would be CMS I’m making.

public function _init_engines() {
    $this->_session_engine = $this->_dep['SessionEngine'];
    $this->_login_engine = $this->_dep['LoginEngine'];
    if ($this->_dep['User'] == false) return;   
    $this->_security_engine = $this->_dep['SecurityEngine'];
    //Other engines go here.......
}

So I let system start session and setup session vars, then check if user is logged in. If user isn’t logged in LoginEngine takes care of that and loads ‘Login’ module. Once Login module is loaded, I don’t want other engines to be instantiated since they are not needed. I could have used die or exit but that would stop whole script from executing. Like this, My script finishes executing, and other things that aren’t engines, like benchmarks and some other stuff still get executed which is just what I want. Again, should I reconsider my logic here or is this way OK in your opinion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:49:17+00:00Added an answer on June 15, 2026 at 3:49 am

    return with no value is OK if:

    1. You interface says that explicitly – docblock states @return void (if no result value needed in the function) or something like @return sometype|null where sometype is string, int, etc.
    2. Code that uses return values from such functions/methods checks isset() before using the returned value – this can lead to bugs if people using your code (or yourself) forget to check it.

    return with no value is NOT OK if:

    1. Error occured – use exceptions instead. Exceptions are much more easier to deal with because you can:
      1. catch them anywhere in the outer scope, even globally
      2. pass nice error messages
      3. extend exception classes to provide additional functionality
      4. check exactly what type of exception was thrown
    2. Some particular result type is expected – in that case you may consider some default “empty” result or, again, use exceptions if something gone wrong – it is still much better than isset because it is harder to forget – exception is a “loud” way to say that an error occured.

    And please, don’t ever use die() or exit() to “handle” errors – it is a very bad practice to show technical details of errors to users.

    As for your _init_engines() method – it is really hard to say if it is right or wrong without knowing the rest.

    If you are interested in good examples of OOP in PHP, I would suggest looking at Symfony.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to count the length of a string with PHP. The string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.