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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:35:35+00:00 2026-05-24T15:35:35+00:00

While I’m led to believe its likely just a design choice, is there any

  • 0

While I’m led to believe its likely just a design choice, is there any advantage to initializing properties in PHP to an explicit null?

As a force of habit I find myself doing:

// ...
protected $_foo = null;
protected $_bar = null;
protected $_baz = null;
// ...

Of course, under circumstances where actual data is intended to be present at object instantiation, there is purpose:

// ...
protected $_array = array('a', 'b', 'c');
protected $_boolean = true;
// ...

Is omission of a null initialization value completely functionally equivalent to inclusion of a null initialization? Are there any other caveats? Also, unless a property is type-checked before any assignments would be made, initialization to an empty array seems like similar situation (and I find myself doing that constantly)

  • 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-24T15:35:36+00:00Added an answer on May 24, 2026 at 3:35 pm

    Yes,

    protected $_foo = null;
    protected $_foo;
    

    are completely equivalents.
    As for me great choise is

    • initialize clearly by null, if it will null by default
    • don’t initialize, if it will be overriden in constructor

    It helps you to see default values quickly, helps code be self-documenting

    Don’t initialize array by array() seems to be bad idea because you can’t use some function (ex. array_push, array_map)

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

Sidebar

Related Questions

While database design I used a field name deleted and use it as Boolean.
while i'm using push notification in iphone with local server(used php), not able to
While most of the time I'd just use file_get_contents and CURL, I can't get
While googling I could find only feistel ciphers and didn't find any relevant information
While Ive seen plenty of examples in PHP, can't seem to find one in
While reading Wikipedia's page on decltype , I was curious about the statement, Its
While Zope 2.13 have native wsgi support, I haven't been able to find any
While reading through another question here, on creating a URL shortening service, it was
While editing .scm files it would be great if Vim would automatically put the
While my ASP.NET project uses version 3.5 of the framework , the event log

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.