<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1040416" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1040416</link>
    <description></description>
    <language>en</language>
          <item>
    <title>Its OK, but why you use</title>
    <link>https://www.webmaster-forums.net/server-side-scripting/php-classes-issues-and-samples-class-noobs-me#comment-1227982</link>
    <description> &lt;p&gt;Its OK, but why you use parent::merge() in getName method of Class2 against $this-&amp;gt;merge()  ?&lt;/p&gt;
 </description>
     <pubDate>Mon, 21 Jan 2008 00:22:42 +0000</pubDate>
 <dc:creator>carloncho</dc:creator>
 <guid isPermaLink="false">comment 1227982 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>You&#039;re heading down the</title>
    <link>https://www.webmaster-forums.net/server-side-scripting/php-classes-issues-and-samples-class-noobs-me#comment-1227684</link>
    <description> &lt;p&gt;You&#039;re heading down the right track with wanting to factor out that code.&lt;/p&gt;
&lt;p&gt;Firstly, you might be able to eliminate both bits of boilerplate without the fetch function.&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;Greg wrote:&lt;/strong&gt; 1. Using of initial values of FALSE:&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Is there any reason not to fetch the $sales values in the constructor?  That way you do one DB call and that&#039;s it.  You can add a sync method to update the $sales values, too.  So now you won&#039;t have to test if the value has been fetched or not, instead you can assume it has been.&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;Greg wrote:&lt;/strong&gt; 2. The use of RetType&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Just thinking aloud here: maybe you could decouple the display from the business logic by creating another set of classes dedicated to display.  If you have a Sales class, then maybe create a DisplaySales subclass which contains all the formatting rules ($retType stuff).  Your logical classes then can return only values, and your frontend person will only use the Display classes.  This way you can even update the display behaviour without modifying the business logic code.&lt;/p&gt;
&lt;p&gt;Secondly, as for the fetch function, it seems like using callbacks would fit right in.  Something like:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;public function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$what&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;T&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$retType&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;VALUE&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; return &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;call_user_func&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(array(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;get&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$what&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// the caller:&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;fetch &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;SalesRatio&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;A&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;DISP&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;That&#039;s totally untested, but it should give you an idea.  However, if you can lose the boilerplate as I suggested at first then it may not be necessary.&lt;/p&gt;
 </description>
     <pubDate>Sun, 30 Dec 2007 16:41:09 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1227684 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Here is another one on</title>
    <link>https://www.webmaster-forums.net/server-side-scripting/php-classes-issues-and-samples-class-noobs-me#comment-1227662</link>
    <description> &lt;p&gt;Here is another one on classes... &lt;/p&gt;
&lt;p&gt;For the data our reports generate, all but one has this issue: all data that is used in the report is in group A or group B, and sometimes we need info from the sum of both. Well I have that handled no problem each &quot;get&quot; function has a parameter $limit which is set to either &#039;A&#039;, &#039;B&#039; or &#039;T&#039; (for total), and defaults to &#039;T&#039;&lt;/p&gt;
&lt;p&gt;Also, each &quot;get&quot; function get passed a Constant that tells if it is returning an actual value (to be used in another calculation) or a formatted value for display directly on the page.&lt;/p&gt;
&lt;p&gt;I have it defined similar to this:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$sales &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= array(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;A&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;B&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;T&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;br /&gt;public function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getSales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$retType&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;VALUE&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$sales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]===&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// Value has not yet been defined so set it&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;T&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;T&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getSales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;A&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] + &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getSales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;B&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// Make necessary calls to database for the values&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // THIS CODE HERE IS ALL THAT IS REALLY DIFFERENT PER WHAT VALUE&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // WE ARE TRYING TO GET. THE REST OF THE FUNCTION IS THE SAME&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // FOR ALL VALUES OTHER THAN THE ACTUAL VARIABLE NAMES &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$whatever&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$retType&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;VALUE&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;$&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;number_format&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sales&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;],&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Here is my logic on doing this way:&lt;/p&gt;
&lt;p&gt;1. Using of initial values of FALSE:&lt;/p&gt;
&lt;p&gt;Most items being &quot;got&quot; are being used within other &quot;get&quot; functions (ie. getSalesRatio(&#039;A&#039;) would need the sales figures for group A and the total sales to return a % of how much group A did). So since a value may be used several times, I only want to make one call to the DB. This way once it is set, it merely returns the value based on it&#039;s formatting options.&lt;/p&gt;
&lt;p&gt;2. The use of RetType&lt;/p&gt;
&lt;p&gt;I want to strip as much &quot;coding&quot; as possible off of the web pages, just have two lines, one to include the Report class and one line to initialize it. After that I want to be able to just do (class assigned to $rep and DISP is one of the defines in the class to tell it to display the number formatted):&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Group A Sales: &amp;lt;?= $rep-&amp;gt;getSales(&amp;#039;A&amp;#039;,DISP) ?&amp;gt;&lt;/code&gt;&lt;br /&gt;
instead of&lt;br /&gt;
&lt;code&gt;Group A Sales: $&amp;lt;?= number_format($rep-&amp;gt;getSales(&amp;#039;A&amp;#039;,DISP),2) ?&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;and yes, after previewing this post, I see I could make it even better by having a separate &lt;strong&gt;$rep-&amp;gt;getSales(&#039;A&#039;)&lt;/strong&gt; and &lt;strong&gt;$rep-&amp;gt;dispSales(&#039;A&#039;)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Again, for our reports, there are many of these used and some displayed in more than one place on a report, so simplifying final HTML output is key. (note, some functions return whole #&#039;s, some are currency values, some are percentages, so with this, the HTML coder doesn&#039;t have to worry about how to format a number given by the report class, (s)he just tells it that they need it formatted.&lt;/p&gt;
&lt;p&gt;Now that I have given that example for others to possible use if they have something similar, here is my question:&lt;/p&gt;
&lt;p&gt;How can I simplify this more? As you can see in my code, other than final formatting, the code for each function is about the same except for where it initially needs the data from the database (or calculating from other values). So I would like to make a function like the following:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;public function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$what&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$limit&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;T&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$retType&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;VALUE&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;&amp;nbsp; { ... }&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
where I can call it &lt;strong&gt;$rep-&amp;gt;fetch(&#039;sales&#039;,&#039;A&#039;,DISP)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;this way all the code to check to see if it is already set, if you are asking for a total and checking the formatting, are in the main fetch function and the code to actually retrieve the values are in a private function.&lt;/p&gt;
&lt;p&gt;I am thinking along the lines of this, once you figure out you need fresh values (any error checking would be added  as well)&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;eval(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;$this-&amp;gt;&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$what &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;[$limit] = get&#039; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$what &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;($limit);&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;); &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;so that if $what=&#039;Sales&#039; it would evaluate into:&lt;br /&gt;
&lt;code&gt;$this-&amp;gt;Sales[$limit] = getSales($limit);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Any thoughts of another way of doing this, knowing I have about 20 different GET functions needed so using &quot;switch&quot;  would not be good due to the messiness of the code. &lt;/p&gt;
&lt;p&gt;-Greg&lt;/p&gt;
 </description>
     <pubDate>Thu, 27 Dec 2007 16:42:44 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1227662 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Given that the merge method</title>
    <link>https://www.webmaster-forums.net/server-side-scripting/php-classes-issues-and-samples-class-noobs-me#comment-1227635</link>
    <description> &lt;p&gt;Given that the merge method is public, I don&#039;t see the benefit of inheritance in that example.&lt;/p&gt;
&lt;p&gt;This style of OOP (Java-like, I guess) isn&#039;t that nice.  And PHP&#039;s version of it is even less tolerable.  It can be futile in many cases.&lt;/p&gt;
 </description>
     <pubDate>Tue, 25 Dec 2007 11:40:54 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1227635 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/php-classes-issues-and-samples-class-noobs-me#comment-1227491</link>
    <description> &lt;p&gt;I considered doing inheritance, but seemed to not fit the true nature of OOP, where for an inherited class, the one class should be a sub class of another (given he usual OOP example...  Class Dog inherits class Mammals, as a dog is a mammal, in my case the report is not an extension of the database, it merely uses it.)&lt;/p&gt;
&lt;p&gt;The big problems with OOP for me is that I&#039;m the type that learns from good workable examples, and in college and most books, the OOP examples are really simple and my mind keeps saying &quot;you could do that easier without a class&quot; lol&lt;/p&gt;
&lt;p&gt;-Greg&lt;/p&gt;
 </description>
     <pubDate>Wed, 19 Dec 2007 13:18:32 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1227491 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/server-side-scripting/php-classes-issues-and-samples-class-noobs-me#comment-1227478</link>
    <description> &lt;p&gt;That code works.  There is no reason that I know of why you couldn&#039;t have an object inside of a class.  In languages like VB.NET or other .NET languages, you have objects and classes all over the place.&lt;/p&gt;
&lt;p&gt;Another way of doing that example is using some simple class inheritance:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;Class1 &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$value1 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= \&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;\&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$value2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = \&quot;\&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public function __construct(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$val1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;=\&quot;\&quot;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$val2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;=\&quot;\&quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;value1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$val1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;value2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$val2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public function merge()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;value1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; . &#039; &#039; . &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;value2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; class Class2 extends Class1&lt;br /&gt;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$data1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = \&quot;\&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$class1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public function __construct(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$full&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;=&#039;&#039;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$last&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$first&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;) = split(&#039;,&#039;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$full&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parent::__construct(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$first&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$last&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public function getName()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return parent::merge();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$test&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = new Class2(&#039;Smith,Joe&#039;);&lt;br /&gt;&amp;nbsp;&amp;nbsp; echo &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$test&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getName&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;();&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Either way works.&lt;/p&gt;
 </description>
     <pubDate>Wed, 19 Dec 2007 01:55:59 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1227478 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
