PHP Classes

very good article

Recommend this page to a friend!

      PHP Classes blog  >  PHP 7 Nested Anonymou...  >  All threads  >  very good article  >  (Un) Subscribe thread alerts  
Subject:very good article
Summary:pretty interesting to know how to manage visibility
Author:Eric Bris
Date:2016-01-10 03:12:11
Update:2016-01-10 17:18:07

  1. very good article   Reply   Report abuse  
Picture of Eric Bris Eric Bris - 2016-01-10 03:36:16
thanks for the article, its very good. It has been pretty interesting to know how to manage the visibility in this new feature. My question is:
What happens if, in the last example, I pass a private property but instead of a scalar it'd be an Object. What happens if inside the nestedClass I modify one of the object's properties?, is the original object going to be modified? thanks

  2. Re: very good article   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2016-01-10 17:18:07 - In reply to message 1 from Eric Bris
I haven't tested it, however I can't think of a reason you would not be able to pass an object.

We have to pass the object, since private properties are not inherited, which results in a new object. Any changes made to the new object will not effect the original object.

You could always set up a method that updates the new object and passes the result back to the main class which would have a method to update the original object. Since it is a private property, it would have to been accomplished inside the main class.