Don't use the internals CMSMS in your code.
Posted: Thu Sep 16, 2010 3:30 pm
Due to the humble beginnings of CMSMS in the php4 world, all of the member variables for the various objects were declared public (php4 didn't have the concept of private and protected member variables).
As a result, there are alot of objects in CMSMS that still have public member variables, and as design goes this is a bad thing. A good developer knows that access to the data should be controlled so that you can manage the integrity of the data, and make sure it's valid for all of the other objects that may use that data.
However we can't go through and 'change' all of this stuff in CMSMS en-mass (as much as we'd like to) for a number of reasons:
a) It'd break alot of stuff in CMSMS, and cost a lot of time to test and fix everything
b) It'd break alot of external modules, plugins and UDT's.
c) We don't have the API's for everything yet, to replace the stuff that would be made inaccessible.
So here are the guidelines:
a) Use the accessors and API's wherever possible
i.e: don't include config.php yourself.
b) Any member variables in any of the CMSMS supplied objects should be considered PRIVATE.
For example, there are a few member variables in $gCms that people are accessing all the time.
i.e: $gCms->variables and $gCms->modules, and a few others
These will be made private, or may be re-arranged over time to something different. They
should be considered CMSMS internal variables, and you should not use them.
We may need to write some further API functions to make some things easier. But for now
consider this your warning.
c) Objects or arrays returned from CMSMS methods, unless stated otherwise should be considered
READ ONLY
i.e this is okay:
this is not:
d) If there is something you need to pull from CMSMS, and can't see an API to do it, ask a clearly explained, well researched question, and we will help you. We won't be responsible for, or support your plugin/module/UDT not working in future versions of CMSMS because you were using internal private data for CMSMS after being warned.
Now that does not mean that I'm gonna go whole hog and mark a bunch of stuff private in 1.9.. but it does mean that you now have the opportunity to
a) submit suggestions as to what is missing in the API
b) change your code to work properly so that hopefully it will have longevity.
As a result, there are alot of objects in CMSMS that still have public member variables, and as design goes this is a bad thing. A good developer knows that access to the data should be controlled so that you can manage the integrity of the data, and make sure it's valid for all of the other objects that may use that data.
However we can't go through and 'change' all of this stuff in CMSMS en-mass (as much as we'd like to) for a number of reasons:
a) It'd break alot of stuff in CMSMS, and cost a lot of time to test and fix everything
b) It'd break alot of external modules, plugins and UDT's.
c) We don't have the API's for everything yet, to replace the stuff that would be made inaccessible.
So here are the guidelines:
a) Use the accessors and API's wherever possible
i.e: don't include config.php yourself.
b) Any member variables in any of the CMSMS supplied objects should be considered PRIVATE.
For example, there are a few member variables in $gCms that people are accessing all the time.
i.e: $gCms->variables and $gCms->modules, and a few others
These will be made private, or may be re-arranged over time to something different. They
should be considered CMSMS internal variables, and you should not use them.
We may need to write some further API functions to make some things easier. But for now
consider this your warning.
c) Objects or arrays returned from CMSMS methods, unless stated otherwise should be considered
READ ONLY
i.e this is okay:
Code: Select all
global $gCms;
$config = $gCms->GetConfig();
$foo = $config['root_path'].'/foo';
this is not:
Code: Select all
global $gCms;
$config = $gCms->GetConfig();
$config['root_path'] .= '/foo';
Now that does not mean that I'm gonna go whole hog and mark a bunch of stuff private in 1.9.. but it does mean that you now have the opportunity to
a) submit suggestions as to what is missing in the API
b) change your code to work properly so that hopefully it will have longevity.