Dana Ross
1 min readJan 8, 2016

--

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 _.property() 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.

--

--

Dana Ross
Dana Ross

Written by Dana Ross

Building the web since 1996. Full-stack developer, but love front-end tech. I also socialize feral and abused cats.

Responses (1)