Created
November 3, 2011 15:28
-
-
Save berkes/1336778 to your computer and use it in GitHub Desktop.
Purrfect Drupal Coding Guideline Helper: Completely randomise your array and object usage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Usage | |
* $inconsistent_view_thingy = views_get_view("some_view_name"); | |
* $more_inconsistent_view_thingy = rand_obj_or_array($inconsistent_view_thingy); | |
*/ | |
function rand_obj_or_array($thing) { | |
$det = rand(0,2); | |
switch ($det) { | |
case 0: # Leave as is | |
return $thing; | |
case 1: # Turn into a stdclass object. | |
foreach($thing as $key => $value) { | |
$other_thing->$key = $value; | |
} | |
return $other_thing; | |
case 2: # Turn into an array. | |
return (array) $thing; | |
case 3: # Turn into an array with drupalish '#keys'. | |
$other_thing = array(); | |
$thing = (array) $thing; | |
foreach($thing as $key => $value) { | |
$other_thing["#{$key}"] = $value; | |
} | |
return $other_thing; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment