The difference is that tools like Less / Sass provide all these features of generating a dynamic CSS very close to the vanilla CSS. The syntax of a Less file can easily be written and understood by a CSS developer as it is not very different from what he is accustomed to. Already doing this with PHP would require knowing a new language.
LESS file taken from link :
@base: #f938ab;
.box-shadow(@style, @c) when (iscolor(@c)) {
-webkit-box-shadow: @style @c;
box-shadow: @style @c;
}
.box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) {
.box-shadow(@style, rgba(0, 0, 0, @alpha));
}
.box {
color: saturate(@base, 5%);
border-color: lighten(@base, 30%);
div { .box-shadow(0 0 5px, 30%) }
}
CSS file result code above:
.box {
color: #fe33ac;
border-color: #fdcdea;
}
.box div {
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
Notice that the syntax is very close. Many tools even implement a syntax when they know it will be officially implemented in CSS in the future. For example, I've seen tools that used mixins from the grid exactly with the grid syntax that is present in the CSS today. This allows the developer to be able to migrate to the latest CSS without changes to their code.
Already, providing the CSS code via PHP does not present any serious problems. By correctly sending the HTTP response headers and properly formatting the CSS, you will have no problems. One difference is that while tools like Less / Sass generate a static CSS file, PHP will generate the file for each request; this can affect the response time of the request depending directly on the execution time of the PHP code. One of the advantages of using PHP to manage this is the ease of controlling all HTTP response headers, especially cache-related ones.
Below is a compiled list of differences cited. The sign next to it indicates which tool has the best results for each characteristic as I see it:
Code syntax;
- LESS / SASS approximate their syntax for vanilla ; ✓
- PHP has a completely different syntax;
Response time;
- LESS / SASS generate a static CSS file; ✓
- PHP requests to be executed with each request, which can increase response time;
Need for HTTP response headers;
- LESS / SASS headers are managed by the server itself; ✓
- PHP requires you to manually control the headers;
Managing HTTP Headers;
- LESS / SASS headers are managed only by the server;
- PHP enables you to manage all headers; ✓
Another possible difference may also be the possibility of sending CSS via server push of HTTP / 2. I do not know if form forms would be possible in an equivalent way.