Note that there are some explanatory texts on larger screens.

plurals
  1. POFatal error: Using $this when not in object context
    text
    copied!<p>I'm creating my class like I always do. I create the member variables, I setup the setter and getter and the I use $this to call the values of the member variables. but for some reason now I'm get the <strong>fatal error: Using $this when not in object context</strong></p> <p>Here is the regular php file which should populates the member variables with their value</p> <pre><code>try { $add_advert = new Site(); $add_advert-&gt;add_time = mysqli_real_escape_string($link, $_POST['time']); $add_advert-&gt;add_url = mysqli_real_escape_string($link, $_POST['URL']); $add_advert-&gt;add_advertisement($_FILES); $feedback = "&lt;div class='succes'&gt;Advertisement succesfully added!&lt;/div&gt;"; } catch(Exception $e) { $feedback = "&lt;div class='error'&gt;"; $feedback .= $e-&gt;getMessage(); $feedback .= "&lt;/div&gt;"; } </code></pre> <p>the member variables:</p> <pre><code>class Site { protected $add_url; protected $add_time; protected $extend_id; </code></pre> <p>the setter and getter:</p> <pre><code>public function __set($p_sProperty, $p_sValue) { switch($p_sProperty) { case "add_url": $this-&gt;add_url = $p_sValue; break; case "add_time": $this-&gt;add_time = $p_sValue; break; case "extend_id": $this-&gt;extend_id = $p_sValue; break; } }//end of setter public function __get($p_sProperty) { $vResult = ""; switch($p_sProperty) { case "add_url": $vResult = $this-&gt;add_url; break; case "add_time": $vResult = $this-&gt;add_time; break; case "extend_id": $vResult = $this-&gt;extend_id; break; } return $vResult; }// end of getter </code></pre> <p>and the function where I use the $this object (it's only a part of the function), it's the $this->add_time that is causing the problem:</p> <pre><code>public static function add_advertisement($files) { global $link, $userid, $useridentify; if(!isset($files['image']['tmp_name']) || empty($files['image']['tmp_name'])): throw new exception("No image given, enter an image please."); endif; if($_POST['URL'] == NULL || $_POST['URL'] == "http://"): throw new exception("No url given, enter a valid url please."); endif; if($_POST['time'] == NULL): throw new exception("You did not select any option to advertise. Select one of the available advertising options."); endif; if(!$path = Uploader::upload_file($files, 'images/', 'gif|jpg|jpeg|jpe|png', 300000)): throw new exception("Could not upload the image."); endif; if(self::get_balance() &gt;= $this-&gt;add_time): </code></pre>
 

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