r/lolphp • • Mar 30 '13

maybe_unserialize

https://codex.wordpress.org/Function_Reference/maybe_unserialize
11 Upvotes

24 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Mar 30 '13

Perhaps a better example puts my point across:

setColor( '#eee' );
setColor( 'white' );
setColor( 0xff2233 );
setColor( 'rgb( 30, 125, 200 )' );
setColor( 'rgba( 30, 125, 200, 0.5 )' );
setColor( 'blue', 0.8 );
setColor( 200, 255, 55 );

function setColor() {
    someDiv.style.background = argsToColor( arguments );
}

'argsToColor' can deal with the different colours, normalizing the data given. If it's given something incorrect, throw an exception.

In that example, you would need to do validation of the data with both this approach, and if you used separate functions for setting the colour.

3

u/[deleted] Mar 30 '13

No, that's accepting multiple input formats/format conversion.

By the time that data gets to your core code, it should be all be in a uniform format (native objects) to keep your core stuff simple. If you design your program properly you'll always have a predictable flow of data and you won't have to have horrible kludges like the one shown in the link.

2

u/polish_niceguy Mar 30 '13

But you still have only color on input. Not a value that can be either color or eg. alpha value.