You can't use function-calls to initialize class member variables.
You can't use function-calls to initialize class member variables. Class YourClass { private $salty; public function __construct() { $this->salty = sha1('salty'); } } is the one way to initialize your variable. EDIT Even, e.g. , a simple concatenation of two constant strings is not allowed (protected $_string = ' 'World!
';). The evaluation of class properties happens at compile time, so the usage of constructs that depend on run-time information is illegal.... This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated. (Properties).
Bingo! Right on the mark! Thanks for that.
Any idea why this is? – Mr_Chimp Nov 18 '09 at 12:19 It's because your class is just a data structure. You always need to call a function to set them to some values.In your case it's the constructor function.
– toto Nov 18 '09 at 12:27 1 Added some explanation. Actually it's a problem of when in the execution process the member variables are evaluated. – Stefan Gehrig Nov 18 '09 at 12:31 That makes a lot of sense.
Thanks. – Mr_Chimp Nov 18 '09 at 12:41.
Just declare the variable as null and then initialize it in your constructor. Private $salty = null function __construct() { $this->salty = sha1('salty'); }.
I didn't try to "handle a function as a variable". You added the $ in "$sha1()" yourself. You do have a point when you say that I should be using hash() instead of sha1().
BTW, try to reply to the comment that you're replying to, otherwise we get a thread full of "answers" which aren't. – Mr_Chimp Nov 18 '09 at 12:58 Ah, I'm sorry for creating a new answer. I'm new here.. I was reffering to the answer of Pablasso, not your post.
– Ben Fransen Nov 18 '09 at 13:00 Oh! Well, that makes sense...I hadn't even spotted that in Pablasso's answer! No worries, pull up a chair, make your self comfortable, etc!– Mr_Chimp Nov 18 '09 at 13:11.
$sha1() won't function because you're trying to handle a function as a variable. And when you're working on a better login mechanism why not start using: $this->salty = hash("SHA512", "salty"); Additionally you can create a salt hash and add it with your password. This addition gives you a little overhead because you will have to save the salt in a db-table too and retreive and combine it when you are validation (user)credentials.
Hope it helps you!
It doesn't, but thanks for trying! – Mr_Chimp Nov 18 '09 at 12:32.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.