0

I am having array like bellow.I don't understand how it is created.

 xyz Object ( [foo] => 10 [foo1:protected] => Array ( [b] => 5 [b1] => 6 ) )

my questions

  • What is xyz

  • How can i get the value of b1

  • How this array is created

  • How :protected is used in array

  • What is the difference between this one and normal or stdobject array

    Thanks in advance

1
  • xyz is an object, not an array. Read the manual. Commented Sep 19, 2011 at 12:48

2 Answers 2

1

This is an instance of class xyz which contains fields : foo and foo1.

<?php
 class xyz
  {
     var $foo=10;
     protected   $foo1=array("b"=>5,"b1"=>6);
     public function getB1() { return $this->foo1["b1"];}
  }

  $a=new xyz();
  print_r($a);

// print $a->foo1["b1"]; // can't be accessible due to protection
  print $a->getB1();
?>
Sign up to request clarification or add additional context in comments.

2 Comments

$avd :how can i extract b1 value
@gowri - protected members of class are not accessible outside the class definition. You can "encapsulate" it via a public method.
1

1) I believe that is the object or class name (can't remember which).

2) You can't outside of the class unless you have a public getter for the array (it's protected).

3) It's not an array, it's an object. It is initialised somewhere in your code.

4) Protected is a class access keyword, it's not used with arrays.

5) stdClass (assuming that's what you mean) wouldn't have a set var protected (somebody correct me if that's wrong).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.