1

null 値を指定されたデフォルト値に変換するための教義の関数を探しています。したがって、IsNull(A, B) は、A が null の場合は B を返し、それ以外の場合は A を返す必要があります。教義にはそのような機能がありますか?

4

2 に答える 2

1

オブジェクトから null 値を取得することについて話している場合は、エンティティにメソッドを記述します

<?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 に答える