Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check valid object of class in smarty?

Tags:

php

smarty

Is there any function in smarty to check valid object of class in smarty?

Suppose $obj is having some value or not.

How to check $obj is object of 'TestClass' or not in smarty?

like image 283
Somnath Muluk Avatar asked Dec 04 '22 14:12

Somnath Muluk


2 Answers

This is the way to check variable is object of specific class in Smarty.

if( true eq isset($obj) && true eq is_object($obj) && $obj instanceof 'TestClass' ){
//do something
}
like image 126
Somnath Muluk Avatar answered Dec 11 '22 08:12

Somnath Muluk


this works in Smarty2 and Smarty3:

{if $obj instanceof TestClass}
  …
{/if}
like image 44
rodneyrehm Avatar answered Dec 11 '22 07:12

rodneyrehm