dimanche 3 mars 2019

PHP if condition inside "a class"

I know that inside a class I cannot put a naked php code and need to put it in a function but I still don't know how to do it, please help me and correct the following code:

class AmazonProductAPI
{
    /**
     * Your Amazon Access Key Id
     * @access private
     * @var string
     */
    private $which_key = rand(1,2);

    if ($which_key == 1) {
        private $public_key     = "public_key1";
        private $private_key    = "private_key1";
        } else {
        private $public_key     = "public_key2";
        private $private_key    = "private_key2";
        }
}

I'd be grateful for any help, thanks!

Aucun commentaire:

Enregistrer un commentaire