Skip to content

Instantly share code, notes, and snippets.

@OZZlE
Last active January 15, 2021 18:20
Show Gist options
  • Save OZZlE/f635bbff3ab15b4d433c9c0310956957 to your computer and use it in GitHub Desktop.
Save OZZlE/f635bbff3ab15b4d433c9c0310956957 to your computer and use it in GitHub Desktop.
PHP equivalent of "modern" sass/less
<?php
// index.php
/* We assume that a designer will ask us one day to increase/decrease all body texts
this website was made in 2010 and we're changing platform now but "sure" this is
going to happen soon :D "In the next project" :-d
Also Search & replace '1em' is very trixy, cannot be done reaaallly! IMPOSSIBLE!
*/
$GLOBALS['fontSizeDefault'] = '1em';
class MixinC { // ... }
class MixinB extends MixinC { // ... }
class MixinA extends MixinB { // ... }
// controller/routeX.php
$GLOBALS['fontSizeDefaultCurrent'] = $GLOBALS['fontSizeDefault'];
// Component.php
$GLOBALS['fontSizeDefaultCurrentPage'] = $GLOBALS['fontSizeDefaultCurrent'];
class Component extends MixinA
{
public $fontSize = $GLOBALS['fontSizeDefaultCurrentPage'];
public __construct() {
// damn... designer wanted different for this component
// lets undo all these cool useful mixins and variables
$this->fontSize = '1.2em';
}
}
@matthew-dean
Copy link

Yes, one should never do that. But you can produce bad code with any language. I think both Sass and Less warn in documentation to be careful with deep nesting (or they should).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment