I have a class:
class Test{ public $AppCount; public $Apps; // When $AppCount is accessed I want to return count( $this->Apps )}
When I access property $AppCount
, I want to return count( $this->Apps )
.
Rather than having to declare an exposing function for this property and making it private, can I use a getter function like C# and Java have?
Obviously the __get
is not what i want in this case as the property does already exist.
For the comments
I have this and it does not run the function when i try and access the property:
class ProjectSettingsViewModel{ public $ProjectAppCount = 0; public $ProjectApps = array(); public function __get( $property ) { switch( $property ) { case "ProjectAppCount": return count( $this->ProjectApps ); break; } }}
If the code seems okay, it must be something else going wrong.