I'm making a PHP script which works with polynomials and monomials (an example of monomial is 42xk^2c^3d
). The Monomial
class is defined as follows:
class Monomial {
public $coefficient; // i.e. 42
public $letters; // an array of Letter objects
public $literal; // i.e. xk^2c^3d
/* Code */
}
Now, in my applications I use both the array of letters and the literal variable. I don't want to update "by hand" the literal
variable whenever I update the monomial (e.g. when adding something to it): instead, I want it to be dynamical, so that accessing it calls a function to "build" it. Any ideas?