Note that there are some explanatory texts on larger screens.

plurals
  1. POI need to understand classes
    primarykey
    data
    text
    <p>I am writing a new booking system seeing as one I have written before is now years old and looking shoddy. I want to write one that is very flexible and portable and I want use classes.</p> <p>I am new to classes and OOP in the php language, I've written one class before and that went well. However I am confusing myself now with this. This is what I have so far:</p> <pre><code>class Order { protected $require_gender = false; protected $require_age = false; protected $require_names = false; protected $require_address = false; protected $require_contact = false; protected $require_dates = false; protected $require_additional = false; function __construct() { foreach(func_get_args() as $arg) { switch($arg) { case "names": case "name": $this-&gt;require_names = true; break; case "age": $this-&gt;require_age = true; break; case "mf": case "gender": $this-&gt;require_gender = true; break; case "address": $this-&gt;require_address = true; break; case "contact": $this-&gt;require_contact = true; break; case "date": case "dates": $this-&gt;require_dates = true; break; case "additional": $this-&gt;require_additional = true; break; } } } } class Person extends Order { private $gender; private $age; private $names = array('first' =&gt; "", 'last' =&gt; "", 'full' =&gt; ""); private $address = array( '1' =&gt; "", '2' =&gt; "", '3' =&gt; "", '4' =&gt; "", 'Postcode' =&gt; "", 'Country' =&gt; ""); private $contact = array('telephone' =&gt; "", 'email' =&gt; ""); private $dates = array(); private $additional; private $active; function setGender($var) {$this-&gt;gender = $var;} function setAge($var) {$this-&gt;age = $var;} function setNames($var) {$this-&gt;names = $var;} function setAddress($var) {$this-&gt;address = $var;} function setContact($var) {$this-&gt;contact = $var;} function setDates($var) {$this-&gt;dates = $var;} function setAdditional($var) {$this-&gt;additional = $var;} function setActive($var) {$this-&gt;actrive = $var;} } </code></pre> <p>So far I guess, so good. But now I am confused. Because I figured that the so called 'superclass' or parent, would be the clients order. As that is what they are doing, they are ordering tickets. And then underneath that they would need to add as many people as they want. </p> <p>I also want to (to make it portable) be able to set requirements, for each booking system this is used as the requirements will need to change. Not everyone will want to know dates, for example, or the postal address. This doesnt vary by <em>person</em>, but by each time this code is used. So i figured logically I would write:</p> <pre><code>$order = new Order("names","address","dates"); $p = new Person(); </code></pre> <p>Then, I would be setting up a <code>new Order</code> with the requirements that I want to use <code>names</code>, <code>address</code> and <code>dates</code>. This way then, I figured, the person object would react accordingly and only allow those things to be set and only deal with those parameters when asked to. But then I find out - that when I create <code>new Person()</code>, it automatically runs <code>class Orders()</code> too! Which I don't want it to do. I want <code>Orders()</code> to be the overlord that sets all the requirements and generally governs the whole order, and person to just be a person inside that order.</p> <p>I am not sure if my problem is because I am using <code>extend</code> instead of <code>implements</code> or something like that, But could someone explain what I should be changing or doing next please? I am eager to learn.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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