这是不起作用的代码:
class MyClass
{
const myconst = 'somevalue';
private $myvar = array( 0 => 'do something with '.self::myconst );
}
Run Code Online (Sandbox Code Playgroud)
似乎类常量在"编译时"不可用,但仅在运行时.有谁知道任何解决方法?(定义不起作用)
谢谢
我一直使用“返回状态代码”方法来管理错误。看来异常现在是管理错误的最佳方式。
但它们真的是最好的方法吗?我读过类似异常比 GoTo 最糟糕的东西
您知道一些关于异常和错误管理的好文章/帖子/书籍吗?
我希望 Sonarqube 基于 Angular Material 分析我的 Angular 应用程序。
有这种样式:
.some-class {
mat-icon {
color: red;
}
}
Run Code Online (Sandbox Code Playgroud)
由于 Angular Material 通过 angular.json 中的配置全局包含,Sonarqube 似乎无法看到 mat-icon 并喊出一个错误:
Unexpected unknown type selector "mat-icon"
有解决方法吗?一个配置?
假设你有这样的功能:
SmartPtr<A> doSomething(SmartPtr<A> a);
Run Code Online (Sandbox Code Playgroud)
像这样的类:
class A { }
class B : public A { }
Run Code Online (Sandbox Code Playgroud)
现在我这样做:
SmartPtr<A> foo = new B();
doSomething(foo);
Run Code Online (Sandbox Code Playgroud)
现在,我想从中取回一个SmartPtr<B>物体doSomething.
SmartPtr<B> b = doSomething(foo);
Run Code Online (Sandbox Code Playgroud)
可能吗 ?我需要做什么样的铸造?
现在,我发现了一些我认为难看的东西:
B* b = (B*)doSomething().get()
Run Code Online (Sandbox Code Playgroud)
重要说明:我没有任何访问权限SmartPtr和doSomething()代码.
我想解析几种文件格式.我想知道是否正确的OOP"冒风险"创造一个无用的对象.
class ParserFactory
{
private fn;
public function ParserFactory(fn)
{
this->fn = fn;
}
public function getParser()
{
a = new FormatAParser(this->fn);
if ( a->isValid() )
{
return( a );
}
b = new FormatBParser(this->fn);
// ... and so on...
}
}
class FormatAParser
{
/*
The object is telling us if is able to continue to work...
**CLEAN OR DIRTY DESIGN ?**
*/
public function isValid()
{
header = SomeConversionAndReadingStuff();
if ( header != "formatA" )
{
return(false)
} …Run Code Online (Sandbox Code Playgroud)