[development] need a standard for contrib node build_mode constants

larry at garfieldtech.com larry at garfieldtech.com
Mon May 18 19:13:59 UTC 2009


Peter's suggestion may work for D6, but for D7, I refer people to 
Eaton's "How to make good APIs" session from DCDC.  Digest version: If 
you expect people to extend your list of flags/constants/modes, for the 
love of god use strings, not ints.  Ints WILL break.  Don't be stupid, 
use strings.

So it sounds like if we expect people to extend the build modes from 
contrib, then core should switch from ints to strings anyway.  Who wants 
to roll the patch? :-)

--Larry Garfield

Peter Wolanin wrote:
> The reason I was suggesting sticking with ints is that strings are
> cast to int 0 during comparison:
> 
> php -r"var_dump('cck' == 0);"
> 
> bool(true)
> 
> And core has code like:
> 
> modules/upload/upload.module:363:  if ($node->build_mode == NODE_BUILD_RSS) {
> 
> modules/book/book.module:710:    if (!empty($node->book['bid']) &&
> $node->build_mode == NODE_BUILD_NORMAL) {
> 
> So if CCK is using ints, that's a potentially serious bug - 0 is
> NODE_BUILD_NORMAL, so I think any string build modes will basically
> end up being this mode.
> 
> -Peter
> 
> On Sat, May 16, 2009 at 11:50 PM, Earl Miles <merlin at logrus.com> wrote:
>> Peter Wolanin wrote:
>>> When doing some cleanup of my Modr8 module, I wanted to define a new
>>> build_mode for use by
>>> http://api.drupal.org/api/function/node_build_content/6
>> I believe there is no need to stick with ints; CCK uses this and I think
>> it's using strings.
>>


More information about the development mailing list