我正在寻找一种用于将空值转换为指定默认值的学说函数。所以 IsNull(A, B) 如果 A 为空,则返回 B,否则返回 A。教义有这样的作用吗?
问问题
1322 次
2 回答
1
如果您正在谈论从对象中获取空值,请在您的实体中编写一个方法
<?php
// Entities/SomeEntity.php
class Foo
{
private $a;
private $b;
// ...
// Your getters and setters are here
// ...
public function myNullFunction()
{
if($this->a === null AND $this->b !== null)
{
return $this->b;
}
elseif($this->b === null && $this->a !== null)
{
return $this->a;
}
else
{
// ... Do something if both are null
}
}
}
然后,您可以在加载对象时使用该功能
$foo = $some_repository->getFooObject();
// The function returning a value that is a or b
$bar = $foo->myNullFunction();
于 2012-01-06T10:01:20.077 回答
0
您可以使用以下包含一些 MSSQL 函数的项目: https ://github.com/naprstek/doctrine-functions
于 2018-11-06T15:03:33.993 回答