Quote:
Originally Posted by allworknoplay
1)You create constants so you can call them statically from the main script. Then pass them as arguments in the isValid() function. How are you able to pass in extra arguments when it's not defined in the function? Or does PHP loosely allow you to add optional arguments without have to specify them when creating the functions? And if so, does this work for regular functions too or just class methods?
|
Functions and methods can accept any number of arguments. The function definition just defines some required, or optional with defaults, arguments. See
function arguments.
Quote:
Originally Posted by allworknoplay
2) $bValidated is set to false. Why do we do this? Is this because we have to declare every property in the class before using it?
|
It would probably (from my understanding of the code) be more useful to name it
$bValid. There is no requirement to declare object properties before using them but
$bValidated is not a property anyway, just a regular variable.
Quote:
Originally Posted by allworknoplay
3) array_shift($aArgs). Since in your example, you passed 3 arguments to the isValid function and then do a foreach loop on the array $aArgs, are you shifting to the 2nd element so that the foreach starts from there, so basically all we get are the 2 constants: NOT_EMPTY and IS_EMAIL....?
|
Yes.
array_shift just removes (and returns) the first item from the array (in this case, of arguments).
Quote:
Originally Posted by allworknoplay
4) After checking if a method exists, I'm a little unclear on what we do here. We set:
$bValidated = $this->$szFunction($szVariable);
I don't see any methods called: $szFunction, so I'm not sure what is going on here.
|
This is a little obscure concept if you've not seen it before: it uses the concept of
variable functions. Say, for example,
$szFunction had a value of 'foo' then the line would actually call
$this->foo($szVariable);.
Quote:
Originally Posted by allworknoplay
5) We then do this:
PHP Code:
if(!$bValidated) { return false; }
But since further up, we already declare $bValidated as false, wouldn't putting a negation operator convert it to true?
|
The value associated with the variable is not changed, the negation is only for the condition used for the if. It is just asking if
$bValidated is false, if so return false.
Quote:
Originally Posted by allworknoplay
6) Since the other methods are set to private. Is the isValid method basically our "getter" method?
|
No. Getter methods only provide an interface to accessing private (or protected) class members. This is just a regular, plain method—no special name.