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

  • Home
  • SEARCH
  • 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 9137409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:06:00+00:00 2026-06-17T09:06:00+00:00

Doing a var_dump on an object from either of the two classes gives the

  • 0

Doing a var_dump on an object from either of the two classes gives the same result

Class Node{
    public $parent = null;
    public $right = null;
    public $left = null;        
    function __construct($data){
        $this->data = $data;                    
    }
}

Class Node{
    public $parent;
    public $right;
    public $left;        
    function __construct($data){
        $this->data = $data;                    
    }
}

For example

$a = new Node(2);
var_dump($a);

returns the following for either of the above classes

object(Node)#1 (4) {
  ["parent"]=>
  NULL
  ["right"]=>
  NULL
  ["left"]=>
  NULL
  ["data"]=>
  int(2)
}

This doesn’t seem to be the case for variables.

$b;
var_dump($b);

If you intend for the property to have a value of null is there a need to explicitly write that since php seems to do it automatically for you?

Also – According to this answer https://stackoverflow.com/a/6033090/784637, C++ gives undefined behavior if you try to get the value of an uninitialized variable. Does C++ automatically set the value of a property in a class to null the way php does, if that property is uninitialized to a value?

  • 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-17T09:06:00+00:00Added an answer on June 17, 2026 at 9:06 am

    No, there is no need to initialize them to null — PHP does this automatically and doing it yourself does not produce any observable difference.

    C++ does not set values of class fields to null (there is actually no “real” null value in C++ unless you count nullptr in C++ 11); it zero-initializes or value-initializes them, which is not the same. You can read about zero- and value-initialization here.

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

Sidebar

Related Questions

I come from PHP background and am used to doing var_dump , echo and
I'm trying to serialize a Doctrine_query object in Symfony : var_dump(serialize($this->pager->getQuery())); The result is
I have parent and child classes as follows: abstract class ParentObj { private $data;
I am doing the following: $type = 'attachment'; $images = $wpdb->get_results($wpdb->prepare(' SELECT p.* FROM
$list = array('red', 'blue', 'white', 'green', 'black', 'orange', 'brown', 'violet', 'magenta'); Before doing var_dump($list),
I'm doing the following in a custom function: $exists = $wpdb->query($wpdb->prepare(' SELECT COUNT(*) FROM
class Group extends dbConnection { //Class for group, for ex. employe and employers. public
I'm currently trying to pass a DB connection as follows: class Test { public
I have an object array $this->result When I echo $this->result I get Array .
I'm trying to detect when an array element is null, but is_null isn't doing

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.