问题描述
我正在使用一个非常简单的代码来测试 phpsass
I am using a very simple code to test phpsass
$sass = new SassParser();
$c = file_get_contents('/_www/_projects/cdn/public_html/test/test.sass');
$css = $sass->toCss($c);
sass 文件非常基础:
The sass file is very basic:
$blue: #3bbfce;
$margin: 16px;
table.hl {
margin: 2em 0;
td.ln {
text-align: right;
}
}
li {
font: {
family: serif;
weight: bold;
size: 1.2em;
}
}
.content-navigation {
border-color: $blue;
color:
darken($blue, 9%);
}
.border {
padding: $margin / 2;
margin: $margin / 2;
border-color: $blue;
}
我收到以下错误:
致命错误:在 D:\_www\_git\phpsass\script\literals\SassNumber.php 中第 201 行出现未捕获的异常 'SassNumberException' 和消息 '
SassNumberException: Number must be a number: Array::26 Source: padding: $margin/2;在 D:\_www\_git\phpsass\script\literals\SassNumber.php 第 201 行
SassNumberException: Number must be a number: Array::26 Source: padding: $margin / 2; in D:\_www\_git\phpsass\script\literals\SassNumber.php on line 201
如果有帮助的话,之前还抛出了以下提示(我尝试更改error_reporting级别,但是提示消失当然没有解决问题):
If it can help, there's also the following notice thrown before (I tried to change the error_reporting level but having the notice disappear of course didn't solve the problem):
注意:第 25 行 D:\_www\_git\phpsass\SassException.php 中的数组到字符串的转换
如果我在 http://www.phpsass.com 上对他们的在线 PHP 编译器使用相同的 sass 代码/try/ 它编译正确...我不明白
If I use the same sass code against their online PHP compiler at http://www.phpsass.com/try/ it compiles correctly... I don't get it
推荐答案
事实上,这是一个纯粹的语法问题.我试图从 sass 代码中删除变量,并意识到它有效 - 效果不佳(margin: 2em 0
变成了 margin: 20
),但不再有错误.
In fact that was a pure syntaxic problem. I tried to remove the variables from the sass code, and realized it worked - not well (margin: 2em 0
became margin: 20
) but there was no error anymore.
我从 http://sass-lang.com/ 获取的 sass 片段不是 sass 而是.scss 格式.SassParser 类有一个参数叫syntax,默认设置为'sass',调用$scss = new SassParser(['syntax' => 'scss'])时需要设置为scss代码>.
The sass snippets that I took from http://sass-lang.com/ were not sass but scss format. The SassParser class has a parameter called syntax, which is set to 'sass' by default and needs to be set to scss when calling $scss = new SassParser(['syntax' => 'scss'])
.
但是我需要解析一个字符串,而不是一个文件,但是如果你传递一个带有 scss 扩展名的文件,你就不需要这个额外的参数.
However I needed to parse a string, not a file, but if you pass a file with a scss extension you don't need this extra parameter.
这篇关于phpsass 返回一个致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!