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 774513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:08:38+00:00 2026-05-14T19:08:38+00:00

Im trying to find best practices to write PHP. I just wonder is this

  • 0

Im trying to find best practices to write PHP.

I just wonder is this a bad habit.

For example, processing variables.

$var = 1
$var = doSomething($var);
$var = doSomething2($var);
$var = doSomething3($var);

It looks a bit awful.

Here is a example of a real code that I just did:

$this->rSum = explode(",", $this->options["rSum"]);
$this->rSum = array_combine(array_values($this->rSum), array_fill(0, count($this->rSum), 0));

If someone could pass me some good tutorials of writing cleaner code generally it would be nice!

Its me again asking stupid questions. 🙂


By the way..

How much automatic processing can there be in models?

I have a model that has a execute method and when I call it, it does a lot of things like reading a definition file and making database queries.

For example

$object = new Object()
$object->setFile("example.txt");
$object->execute();

// Then i can fetch things from it
echo $object->getName();
  • 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-05-14T19:08:39+00:00Added an answer on May 14, 2026 at 7:08 pm

    I really like your (real) code and it’s usually kinda hard for me to like other persons code (I haven’t had much time to dig into ZF but PEAR for instance [they also have their coding standards] is just awful IMO), the first example you gave just seems stupid but regarding the second one, it is really easy to understand at least for me and from the short snippet you provided you seem to have a consistent coding style and be using whitespaces in the right amount and at right places – that counts a lot for clean code (if you don’t believe me just take a look at some Perl snippets).

    I would only like to point out three things:

    1. Semantics: Although rSum is not a awful name for a property it isn’t quite clear what values does it hold, perhaps you could find a more descriptive name for that property?
    2. Variable Reuse: As I said before your first example seems stupid but it’s actually smart to reuse variables for two main reasons:
      1. You don’t waste memory.
      2. And you don’t pollute the scope you’re working with.
    3. Your second “real” example could be cleaner and faster if you use the right functions:

      $this->rSum = array_flip(explode(“,”, $this->options[“rSum”]));

    EDIT: I just noticed the code I provided above is not quite what you’re doing (the 0 was not processed by my brain), here is another working alternative:

    $this->rSum = array_fill_keys(explode(",", $this->options["rSum"]), 0);
    

    There seems to be a lot of people here that don’t like one-liners I however, believe that the the above code is clear, efficient and descriptive – but that may be just me… =)

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

Sidebar

Related Questions

Im trying to find a best practice to load usercontrols using Ajax. My first
I am trying to find the best practice for generating and outputting html which
I'm trying to find out the best practice when removing characters from the start
I'm trying to find the best way to speed up the delivery of the
I'm trying to find the best solution for nonblocking IO via stdin/stdout with the
i am trying to find the best way to display results on my page
I am trying to find the best way to design the database in order
I'm currently trying to find the best way (in term of usability and performance)
I have an interesting query to do and am trying to find the best
Writing my first Linq application, and I'm trying to find the best way to

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.