Hello,

I've got a few questions that may be a bit lame - hope it's OK.

I'm writing a couple of PHP "components" internally for our purposes. 
First I thought they would be just independent groups of classes, 
nothing to it, but then I thought maybe following the eZComponents way 
would be a good thing (especially for I will use or extend few of them). 
So I dove into the implementation guidelines 
(http://www.ezcomponents.org/contributing/coding_standards), most of 
which is very clear and helpful.

However, what I don't quite grasp is the distinction between internal 
properties following traditional getXxx()/setXxx() pattern, and "just" 
properties, for which the magic methods __get()/__set/__isset() are used 
and which operate on $properties property.

Could someone explain (or point to some deeper source):

1) What is/was the rationale behind this separation? I think I 
understand technical consequences, but I fail to see the reasons... The 
guidelines say: "The implementation of the properties happens in the 
__set() and __get() magic methods to allow value bounds checking and 
access control.". Wouldn't that be possible with traditional getters and 
setters? I would be grateful for some example illustration here.

2) What method of deciding which would become an internal property and 
which would become $properties[$name] would you recommend? Any golden 
rule here?

3) Is there any way of making IDE to see/hint which $properties are 
available or is it completely out of reach with this architecture?

4) Also, is this how inheritance is achieved with the $properties?

<?php
class classWithFirstProperty
{
     protected $properties = array();

     public function __set( $name, $value )
     {
         switch ( $name )
         {
             case 'firstProperty':
                 $this->properties[$name] = (string) $value;
                 break;

             default:
                 throw new ezcBasePropertyNotFoundException( $name );
                 break;
         }
     }

     public function __get( $name )
     {
         switch ( $name )
         {
             case 'firstProperty':
                 $this->properties[$name] = (string) $value;
                 break;

             default:
                 throw new ezcBasePropertyNotFoundException( $name );
                 break;
         }
     }
}

class classWithSecondProperty extends classWithFirstProperty
{
     protected $properties = array();

     public function __set( $name, $value )
     {
         switch ( $name )
         {
             case 'secondProperty':
                 $this->properties[$name] = (string) $value;
                 break;

             default:
                 parent::__set( $name, $value );
                 break;
         }
     }

     public function __get( $name )
     {
         switch ( $name )
         {
             case 'secondProperty':
                 $this->properties[$name] = (string) $value;
                 break;

             default:
                 parent::__get( $name );
                 break;
         }
     }
}

$twoPropertyObject = new classWithSecondProperty();
$twoPropertyObject->firstProperty = 123;
$twoPropertyObject->secondProperty = 456;
?>

Would that be correct?

5) Would you recommend to stick with eZC way? Why? Why not?


I would be grateful for any help or suggestions regarding these topics.

Cheers,
Piotrek
-- 
Components mailing list
Components@lists.ez.no
http://lists.ez.no/mailman/listinfo/components

Reply via email to