[wp-hackers] Coding Standards: Functions vs. Classes
michal at srodek.info
Sun Mar 18 07:53:46 UTC 2012
I prefer full objective style of coding (take a look at Zend Framework
- http://framework.zend.com/ ) but unfortunately it could be much
harder to understand for newbie php programmers(it could be advantage
either. objective code = less poor quality plugins).
>When 5.3 is the minimum requirement, using namespaces would give a solution.
Well namespaces can be used with class too. I think that namespaces
are the solution for "wp_" prefix. That's all.
>2. Are there several pieces of data that needs to be constantly passed around between those functions? Use a class.
It's not so simple. There is also something called a visibility. Some
functions should be visible outside the class, some not. Take a look
at e.g. wp-includes/shortcodes.php file. I guess, the do_shortcode()
function should be public, shortcode_parse_atts() not. It's unclear
for me which functions are getters/setters and which could be removed
or changed in the future.
2012/3/18 scribu <scribu at gmail.com>:
>> Is there some reasoning behind the decision to use a set of functions
>> of a class? Or is it coders choice?
> The reasoning goes something like this:
> 1. Use functions.
> 2. Are there several pieces of data that needs to be constantly passed
> around between those functions? Use a class.
> And what about static class variables rather than global variables? WP
>> stopped supporting PHP4 last year, so is there any reason not to use static
>> class variables for new development?
> I don't think new globals were introduced since we dropped PHP4, but I
> haven't see static class variables used yet either.
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers