HN user

frosas

10 karma

https://francescrosas.com

Posts0
Comments12
View on HN
No posts found.

I've being using this trick for years instead of the ugly

    isset($array['key']) ? $array['key'] : null;
thinking I was simply ignoring those stupid "Undefined index" notices.

Now I figure out I was also hiding "Undefined variable" notices when $array was not defined and a ton of potential errors when $array is an object implementing ArrayAccess.

Shame on me.

I agree keyword arguments are a better solution (but probably harder to implement).

Right now this is how I do this:

    function salute($user, array $options = null) {
        $options = (array) $options + array('shout' => false);
        $salutation = "Hi $user!";
        if ($options['shout']) $salutation = strtoupper($salutation);
        return $salutation;
    }

How does one calculate password entropy? I deduced this one:

entropy = log2(symbols^chars)

But using 63 symbols ([a-zA-Z0-9&]) I get 65 bits for Tr0ub4d0r&3, not 28.