(06-22-2021, 02:03 AM)paulbalandan Wrote: If you are not inside a class context, you can use static variables instead.
PHP Code:
static $hasRun;
if ($hasRun !== true)
{
$hasRun = true;
// run your function here
}
I tried this. I tried placing $hasRun above class Configure extends CI_Controller but I get undefined variable. Then I placed it between
class Configure extends CI_Controller
{
static $hasRun; <<<<<<<<here
public function __construct()
And i still get undefined variable.
I put the if ($hasRun !== true) in the __construct()
(06-22-2021, 04:19 AM)paliz Wrote: Its amazing topic
function foo()
{
static $foo_called = false;
if (!$foo_called) {
$foo_called = true;
// etc.
}
}
The problem is that foo runs each time.
(06-22-2021, 12:04 AM)John_Betong Wrote: @richb201 ,
I have not used static before and decided to give it a try... discovered it ONLY works on Class Methods(...).
The following KLUDGE should work which I have tried in:
CI4 -> app/Common.php -> function fred(...)
Code:
//==================================================
function fred($val='Nothing set???', mixed $title='NO TITLE')
: string
{
if( defined('CALL_ONCE_ONLY') ) :
echo '<br> PREMATURE FUNCTION RETURN AND NOT USED';
return '';
endif;
define('CALL_ONCE_ONLY', 'pretty please');
$results = print_r($val, TRUE);
echo $tmp = <<< ____EOT
<div> <br> </div>
<dl class="w88 mga fss bgl bd1 p42" >
<dt> <b> $title </b> ==> </dt>
<dd>
<pre class="tal wrp bga">
<b> $title </b> ==>
<br>
$results
</pre>
</dd>
</dl>
____EOT;
return $result=(string) '';
}//
Following your lead I stuck this in the bottom of _init()
if(defined('RUNONCE')) {
}
else {
$this->get_from_locker(); //bring down this guy's images
define ('RUNONCE','YES');
}
Unfortunately it keeps running get_from_locker() each time.
proof that an old dog can learn new tricks