Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * funny bug with extract and string concat
- * that results in ERR_CONNECTION_RESET (WAMP)
- */
- //custom styles I get from the CMS editor
- $json = '{
- "classname": ".b-1067",
- "styles": {
- "only screen": {
- "background": "#E6F0FA",
- "padding-top": "4rem 0 2rem",
- "margin-top": "0"
- },
- "only screen and (min-width: 720px)": []
- },
- "childStyles": {
- "only screen": [
- ".wrap { max-width: 1200px; }"
- ],
- "only screen and (min-width: 720px)": [
- ".grid__item { width: 50%; }",
- ".grid__item { border-width: 0 0.5rem 0.5rem; }"
- ]
- }
- }';
- //renaming $styles to $data prevents the bug
- $styles = json_decode($json, true);
- extract($styles); //destruct this variable to give me $classname, $styles, $childStyles
- //this outer loop would be the different CMS content blocks
- //removing this loop prevents ERR_CONNECTION_RESET and reveals the error message (undefined index)
- $blocks = array(1,2,3,4,5,6,7,8,9);
- foreach($blocks as $block) {
- foreach($styles as $mq => $attributes) {
- //echo main styles ...
- //echo nested child styles
- foreach($childStyles[$mq] as $style) {
- echo $classname .' '. $style; //ERR_CONNECTION_RESET (WAMP)
- //works:
- //echo $classname;
- //echo ' ';
- //echo $style;
- echo '<hr />';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement