<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1041813" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1041813</link>
    <description></description>
    <language>en</language>
          <item>
    <title>A correction of the first</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-classesfunctions#comment-1232899</link>
    <description> &lt;p&gt;A correction of the first post code (missing bracket):&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;&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;dummy &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$variable&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$variable2 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$variable3 &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$one&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$two&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;$val &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$one &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;+ &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$two&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;$val&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&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;/p&gt;
 </description>
     <pubDate>Sun, 31 Aug 2008 23:05:38 +0000</pubDate>
 <dc:creator>decibel.places</dc:creator>
 <guid isPermaLink="false">comment 1232899 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Hmm, it looks like I really</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-classesfunctions#comment-1232897</link>
    <description> &lt;p&gt;Hmm, it looks like I really should investigate classes a bit more.&lt;br /&gt;
Although, I am a believer in only using things if necessary, rather than it&#039;s there so use it. So as with functions, I will only use classes when it will be worthwhile.&lt;/p&gt;
&lt;p&gt;People use functions too much imo, for the sake of a few lines of code used 2-3 times it&#039;s not always worth it.&lt;/p&gt;
 </description>
     <pubDate>Sun, 31 Aug 2008 19:57:58 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1232897 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>A function would do the same</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-classesfunctions#comment-1232896</link>
    <description> &lt;blockquote&gt;&lt;p&gt;A function would do the same thing, so which would be better?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Neither. I don&#039;t think there&#039;s any need to abstract addition &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;.&lt;/p&gt;
&lt;p&gt;I used to be a function writer guy too, but once I got acquainted with OOP, I just can&#039;t go back. Having a class that abstracts an entity is really nice. You have just one little object variable that holds &lt;strong&gt;all&lt;/strong&gt; the data about an entity, and holds &lt;strong&gt;all&lt;/strong&gt; the methods that can manipulate that entity. &lt;em&gt;All in one neat little package&lt;/em&gt;. You just can&#039;t beat that.&lt;/p&gt;
&lt;p&gt;Say you&#039;re running a dog website. Wouldn&#039;t it make sense to create a class that holds all the dog&#039;s information, and a set of methods that do something to the dog?&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;class &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;Dog&lt;br /&gt;&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;ID&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;description&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;breed&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;__construct&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$ID&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;&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;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// get dog row from database&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // assign that tuples to class variables&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;getName&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;()&lt;br /&gt;&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;&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;name&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;setName&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$name&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;&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;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// change name in database&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // change name in class variable&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&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;Even better yet, you could create a general animal class and have each Dog, Cat, Bird class inherit from the animal class. That would cut down on your code duplication quite a bit. Your app would be a lot easier to maintain.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Isn&#039;t this second accessing of the hard drive for the include file going to be slower than simply having the database connection code in the login.php file?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Yup. But say you change your database from MySQL to Postgre (is that how it&#039;s spelled?). Now you have to change every file in the site that accesses the database because you didn&#039;t abstract the database accessors. &lt;/p&gt;
&lt;p&gt;Maintainability trumps speed in most cases. First make your code readable, maintainable, and reusable, and then refactor it for speed (when it&#039;s needed). I think most programmers would agree. That&#039;s a common theme in a lot of the programming books I&#039;ve read.&lt;/p&gt;
 </description>
     <pubDate>Sun, 31 Aug 2008 16:47:00 +0000</pubDate>
 <dc:creator>teammatt3</dc:creator>
 <guid isPermaLink="false">comment 1232896 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Greg K wrote:
If you have a</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-classesfunctions#comment-1232895</link>
    <description> &lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;Greg K&lt;/em&gt; wrote:&lt;/div&gt;If you have a major site that is calling a database connection every single page, the system will most likely cache that included file in memory and not actually read the drive.&lt;br /&gt;
....but you can have it cache the &quot;compiled&quot; code for faster processing.....&lt;/div&gt;&lt;br /&gt;
Ahh, I will look into that. I suppose, as you said, it&#039;s behind the scenes I need to look at. When php will determine it&#039;s worth caching something and how it does it. How many accesses in a given time or whatever.&lt;br /&gt;
Sounds like something that could be very worth while that in certain sites and circumstances could return noticable performance improvements.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;Greg K&lt;/em&gt; wrote:&lt;/div&gt;It amazes me when I stop to think at what all happens behind the scenes when you call a website anymore.&lt;/div&gt;&lt;br /&gt;
Yeah.&lt;br /&gt;
Having compiled my own kernal in linux, played with apache/php/mysql installs myself, code php/css etc and have a bit of understanding of the way servers work, DNS registrars, nameservers, ISP IP lease and DHCP etc, it is mind boggling that the internet actually works &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/grin.png&quot; title=&quot;Laugh&quot; alt=&quot;Laugh&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Most simple company networks with a few hundred PC&#039;s and a mainframe have major faults and issues, but a huge public one with many hands in the pie and outside influences on anything we do...it is amazing really&lt;/p&gt;
 </description>
     <pubDate>Sun, 31 Aug 2008 16:29:00 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1232895 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>As I&#039;m the type who learns</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/php-classesfunctions#comment-1232892</link>
    <description> &lt;p&gt;As I&#039;m the type who learns off of actual examples and using them, classes were hard for me to get as well. All the &quot;simple&quot; examples just seemed like overkill for things like websites. As you said, an included function file would work just as good.&lt;/p&gt;
&lt;p&gt;It wasn&#039;t until I started reading about the differences between PHP 4 and 5&#039;s classes that I found a use for them. In 5, a classes information is actually protected, where in 4 it wasn&#039;t (ie, in your code, in 4, you can directly access the values of $variable, $variable1, $variable3, where in 5, if the class is defined right, your code that uses the class cannot).&lt;/p&gt;
&lt;p&gt;As for the including of files, for this you have to understand how a server handles calls to the file system and caches that information. If you have a major site that is calling a database connection every single page, the system will most likely cache that included file in memory and not actually read the drive.&lt;/p&gt;
&lt;p&gt;Also, it&#039;s been a while since I looked into it, so don&#039;t remember if it is a setting in PHP or one of the zend products, but there is a way where not only will the code be cached, but you can have it cache the &quot;compiled&quot; code for faster processing (PHP compiles line by line as it is used, and it will save chucks of the final machine code to use over instead of recompiling the lines.&lt;/p&gt;
&lt;p&gt;It amazes me when I stop to think at what all happens behind the scenes when you call a website anymore. Heck. I remember back 14 years ago, we thought it was soooo amazing to have a BBS system that could handle 64 different people dialed into the one computer and how well it handled all 64 accessing the same database at the same time (see &lt;a href=&quot;http://tbbs.org/TBBS.html&quot; title=&quot;http://tbbs.org/TBBS.html&quot;&gt;http://tbbs.org/TBBS.html&lt;/a&gt;).  There is a tremendous amount of file control and processing that goes on on computers. [/oldfartmode] lol&lt;/p&gt;
&lt;p&gt;-The Other Greg&lt;/p&gt;
 </description>
     <pubDate>Sun, 31 Aug 2008 15:18:00 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1232892 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
