nice post.

Hi Sahin,

Your function makes fewer assumptions about the data it’s working with, which is great. In fact, you’ve reduced it to nothing more than a strtoupper() call, so you don’t even need your own function at that point. You could just call strtoupper() directly.

It’s fine for my “pure” function to access $post->post_title. That’ll always be referentially transparent unless $post implements PHP’s magic __get method and does something silly. The main threat to purity in WordPress code is all the global variables WordPress uses, which make functions like get_the_title() return different things at different times.

If we were going for a points-free approach, though, it would be better to use a tested & trusted library function to grab the property’s value & pass it right to strtoupper(). Check out prop() in my Functional Programming Utils library or in Underscore.js. Then you could do something like:

return strtoupper( prop( $post, ‘post_title’ ) );

I think you’ll really like Part 3 when it’s ready. I’m planning to talk about a couple different topics related to handling data inside functional code.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.