如何在smarty中检查类的有效对象?

Som*_*luk 2 php smarty

smarty中是否有任何函数可以在smarty中检查类的有效对象?

假设$obj有一些价值.

如何$obj在smarty中检查'TestClass'的对象?

Som*_*luk 5

这是检查变量是Smarty中特定类的对象的方法.

if( true eq isset($obj) && true eq is_object($obj) && $obj instanceof 'TestClass' ){
//do something
}
Run Code Online (Sandbox Code Playgroud)


rod*_*ehm 5

这适用于 Smarty2 和 Smarty3:

{if $obj instanceof TestClass}
  …
{/if}
Run Code Online (Sandbox Code Playgroud)