Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your function <code>validateText()</code> is a <code>static</code> function; because of this, it doesn't belong to a single "instance" of the class <code>Validation</code> but instead to <em>all</em> of them and, therefore, is not applicable to the <code>$this</code> keyword.</p> <p>Your choices here are to either drop <code>static</code> from the function declaration or to make <code>$errorMsg</code> static itself (which, based on it's definition may be a good way to go):</p> <pre><code>public static $errorMsg = array( 1000 =&gt; 'Some Error', 1001 =&gt; 'Some other error'); static function validateText($value) { if (!empty($value)) { if (ctype_alpha($value)) { return false; } else { return Validation::$errorMsg[1001]; //getting error here } } else { return Validation::$errorMsg[1001];//getting error here } } </code></pre> <p><strong>Add-on</strong> (const versus static)<br> Based on recommended comments, I am also adding in the "appropriate" way to handle your exact situation. The above will fix your error, however, it is not the best way to approach "error messages" as class-properties. Instead of using <code>static</code>, you can setup a list of constant class members using the <a href="http://php.net/manual/en/language.oop5.constants.php" rel="nofollow"><code>const</code></a> keyword (which won't work with arrays, so you'll be creating several variables here instead):</p> <pre><code>class Validation { const SOME_ERROR = 'Some Error'; const SOME_OTHER_ERROR = 'Some other error'; static function validateText($value) { // process value return Validation::SOME_ERROR; } } </code></pre> <p>You can also access these constants from outside of the <code>Validation</code> class via: <code>Validation::SOME_ERROR</code> and, if you have PHP 5.3+, you can use:</p> <pre><code>$v = new Validation(); echo $v::SOME_ERROR; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload