• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Initiate variable only once in php - even if another class extends it

tino

n00b
Joined
Jun 9, 2008
Messages
30
I have a class called logit, please excuse the incorrect formatting.

PHP:
<? 

class logit

var: $logs=array();

// ... does other stuff ... 

?>

Now I have another class that extends logit
PHP:
<? 

class lognot extends logit

if (!in_array($this->logs)) {
array_push($this->logs,$somevariable)
}

?>


Now I have another function that extends logit. Which I call after lognot
PHP:
<?

class lognew extends logit

if(count($this->logs)<1) {
// do something
}
?>

Now I'm running into a problem where it resets $logs when lognew is called.

So I need $logs to be defined as a array on the first instance and for it then to not be initiated after, and to hold what ever values the class's that extend logit enter into this array. The final class lognew will then handle it all if it contains any data.

Thanks for any replies.
 
Last edited:
Can't you just check what $logs contains before deciding if you want to initialize it or not? Please use the code tag next time.
 
Can't you just check what $logs contains before deciding if you want to initialize it or not? Please use the code tag next time.

Apologies I thought I had used the code tag. Edited the original post now.

As I set it as the top of $logs as a var it doesn't seem to want to let me check to see if that variable is empty or doesn't have any data.

I'm probably doing something really stupid or missing some very simple point.
 
As I set it as the top of $logs as a var it doesn't seem to want to let me check to see if that variable is empty or doesn't have any data.
What the heck does that mean?
 
What the heck does that mean?

It means that it initiates the $logs as an array(); every time I call a class that extends this one.

If I do a check before, then it will create a syntax error as its at the start of the class.
 
Back
Top