I have a class that contains a method that performs various database checks. Then it returns the value if it exists.
Here is an example of a basic setup:
PHP class
class myClass{
var $aVar1;
var $aVar2;
function myMethod()
{
}
}
HTML / PHP File
<?php if($myClass->myMethod(): ?>
<?php echo $myClass->myMethod() ?>
<?php endif; ?>
This event occurs several times in my file with different ones methods. My question is that I call the method initially and check if it is false, and then call it again echo.
I could do the following, but in the end we get a variable declaration for each method. Should there be a more professional approach?
<?php
$myMethod = $myClass->myMethod();
if($myMethod): ?>
<?php echo $myMethod ?>
<?php endif; ?>
Is there a more efficient way to do this?
user5483305
source
share