Note that there are some explanatory texts on larger screens.

plurals
  1. POOOP Loop Help Needed
    text
    copied!<p>I have scoured the net and watched endless You Tube vids but cant find an answer to this. Most of what I am finding is for more complex issues and I am just a newbie starting out.</p> <p>I am trying to learn OOP. I took an old PHP example I had lying around and decided to try converting it to oop. All it is is a loop with a counter. Problem is I cant get it to work out at all.</p> <p>My original view page was this...</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;1 Loop&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;h2&gt;1 Loop for age&lt;/h2&gt; &lt;?php $age=18; while ($age &lt;= 20) { echo ("You are " . $age . " years old. &lt;br /&gt; You are not old enough to enter. &lt;br /&gt;&lt;br /&gt;"); $age++; } echo ("You are " . $age . " You may enter!"); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Now I am trying to create a class_lib page and a php page. Here is my class page:</p> <pre><code>&lt;?php class person { public $age; function __construct($persons_age) { $this-&gt;age = $persons_age; } function get_age() { while ($age &lt;= 20) { echo ("You are " . $age . " years old. &lt;br /&gt; You are not old enough to enter. &lt;br /&gt;&lt;br /&gt;"); $age++; } echo ("You are " . $age . " You may enter!"); return $this-&gt;age; echo $this-&gt;age; } } ?&gt; </code></pre> <p>And lastly, my php view:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;1 Loop&lt;/title&gt; &lt;?php include("class_lib.php"); ?&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;1 Loop for age&lt;/h2&gt; &lt;?php $obj = new person(17); echo $obj-&gt;get_age(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Can someone give me a few pointers as to where I am going wrong?</p>
 

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