1

I am getting the following error in the following code:

Class primeField implements field {
    private $intmodulus = '';
    public function generator(){
        return ;
    }

    public function modulus(){
        return $this->$intmodulus;
    }
    public function __construct($modulus , $base=0) {
        if (is_resource($modulus) && get_resource_type($modulus) == "GMP integer"){
            $this->$intmodulus = $modulus;
        } else{
            $this->$intmodulus = gmp_init($modulus , $base); \\line 70
        }
    }
}
$a = new primeField(11);
$a->modulus();

Notice: Undefined variable: intmodulus in /Users/admin/PHP ECC/finitefield.php on line 70 Fatal error: Cannot access empty property in /Users/admin/PHP ECC/finitefield.php on line 70

Why

2 Answers 2

4

The syntax is

$this->intmodulus 

not $this->$intmodulus.

You get an error saying "cannot access empty property" because $intmodulus is undefined and hence accessing it gives NULL. The NULL gets converted into an empty string when you attempt to use it as a property name.

If the value of $intmodulus was the name of a valid property (e.g. if $intmodulus == "intmodulus"), you would be accessing the property with that name.

Sign up to request clarification or add additional context in comments.

2 Comments

Note that $this->$intmodulus is still valid PHP, it just does something different from what was intended.
Thankyou, been about 3 years since I touched PHP, and my mind is a bit numb.
0

$this->$intmodulus should be $this->intmodulus

See the PHP documentation for Variable variables for info on what is happening.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.