Get/Set Behavior Properties

[size=3]NOTE: I’ve modified the below code a bit. If you’re interested in checking this out, please look at issue #264 under development and all source code is attached to that issue.[/size]

I've started to use behaviors as a way around PHP's lack of multiple inheritance. This has worked well except for the fact that only behavior methods are accessible via the owner class.

I have been playing around with a few ways to implement the behavior properties and have settled on these changes to the CComponent class:

I considered placing them in my subclasses of CComponent but I really think they should be in the base component class if behaviors are to be fully supported.

One concern/issue/caveat/problem with this approach is that behaviors must be attached in the constructor because of the application flow. The init() method isn’t called until after the properties are set in a component. But unless there is some architectural reason this is bad practice, I don’t have a problem with it.

I'm sure I will tweak CComponent a little more before I complete my project, however I wanted to put this out there for comments.

Here is a behavior I created:

And here's how I use it:

Nice work! Could you please create a ticket for this? We need time to assess the impact of this enhancement. Thanks.

Thanks Qiang, appreciate the feedback. I will post this as an issue.

I've been running the code for a few days with no ill effects to my knowledge.

I've been thinking some more about this implementation.

The fact that I have to attach behaviors in the constructor is bothersome to me.

The solution I've come up with is to create a "preInit()" event which can be implemented by the subclass if this behavior is required. The preInit() could contain the behavior attachments.

In addition, I've considered adding a framework class override feature to the autoload mechanism. This would allow you to "inject" your own class into the base framework without having to modify framework code. For example, I could create a CComponent class that lives outside of the framework installation but through a special import mechanism would be loaded when CComponent was requested. Again, just a thought.


I've created issue #264 ( for this feature request.

I also went ahead and implemented the preinit() method. :)

In addition, I've fully coded it for you. You just have to "Qiang-ify" it because I use a different coding convention than you.

Happy to help out…