Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy in OOP you do everything in objects?
    text
    copied!<p>We have started to work with PHP developer, i looked at his code and from my perspective this is waste of ink to write stuff like this. I personally dont do OOP. </p> <p>He never answered this question can someone who good with OOP explain.</p> <p>In file <strong>inc/path.php</strong> you define <em>class Path</em> with different variables for path to files and folders</p> <pre><code>class Path { var $path_cnfg = null; /* URLs */ var $url_css = '';//for css url var $url_js = '';//for javascript url var $url_img = '';//for image url /* Paths */ var $path_inc = '';//inc directory path var $path_img = '';//image path function Path() { $this-&gt;path_cnfg = new Config(); /* Setting URL(s) */ $this-&gt;url_css = $this-&gt;path_cnfg-&gt;base_url.'assets/css/'; $this-&gt;url_js = $this-&gt;path_cnfg-&gt;base_url.'assets/js/'; $this-&gt;url_img = $this-&gt;path_cnfg-&gt;base_url.'assets/img/'; /* Setting Path(s) */ $this-&gt;path_inc = $this-&gt;path_cnfg-&gt;root_path.'/inc/'; $this-&gt;path_img = $this-&gt;path_cnfg-&gt;root_path.'/img/'; } } </code></pre> <p>A. Whats the purpose of method <strong>Path</strong> inside class path?</p> <pre><code>function Path() { $this-&gt;path_cnfg = new Config(); /* Setting URL(s) */ $this-&gt;url_css = $this-&gt;path_cnfg-&gt;base_url.'assets/css/'; $this-&gt;url_js = $this-&gt;path_cnfg-&gt;base_url.'assets/js/'; $this-&gt;url_img = $this-&gt;path_cnfg-&gt;base_url.'assets/img/'; /* Setting Path(s) */ $this-&gt;path_inc = $this-&gt;path_cnfg-&gt;root_path.'/inc/'; $this-&gt;path_img = $this-&gt;path_cnfg-&gt;root_path.'/img/'; } </code></pre> <p>B. In <strong>obj.php</strong> you transfer that variables from object <em>$path</em> to array <strong>$data</strong>.</p> <pre><code>$data['path_img'] = $path-&gt;path_img;//Assign image directory path $data['path_root'] = $config-&gt;root_path;//Assign root path $data['url_base'] = $config-&gt;base_url;//Assign base url $data['url_css'] = $path-&gt;url_css;//Assign css directory path $data['url_js'] = $path-&gt;url_js;//Assign javascript directory path $data['url_img'] = $path-&gt;url_img;//Assign url for image </code></pre> <p>What was purpose of having class <em>Path</em> over defining array <strong>$data</strong> by itself and use it derectly? Why we need to go trough all this methods and object to get to same variable ($data) that we could originally defined in 6 lines of code. e.g. </p> <pre><code>$data["path_img"] = $config-&gt;base_url . "assets/img/"; ... $data["url_css"] = $config-&gt;base_url . "/assets/css/" $data["url_js"] = $config-&gt;base_url . "assets/js/" $data["url_img"] = $config-&gt;base_url . "assets/img/" </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