{"id":1372,"date":"2018-01-19T19:22:45","date_gmt":"2018-01-19T19:22:45","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/php-and-classes-page-3\/"},"modified":"2018-01-19T19:24:44","modified_gmt":"2018-01-19T19:24:44","slug":"php-and-classes-page-3","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/php-and-classes-page-3\/","title":{"rendered":"PHP and Classes Page 3"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Rod Kreisler<\/div>\n<div class=\"\">on July 30, 2000<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<div class=\"articlePara\">\nGreat, now what to we do with it?  I&#8217;m glad you asked.  We need to<br \/>\ncreate a few more functions within Style to actually accomplish<br \/>\nanything.  The first thing I&#8217;d like to do is set up my page body so I<br \/>\ndid this:<\/div>\n<div class=\"articlePara\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p><\/span><span style=\"color: #007700\">function\u00a0<\/span><span style=\"color: #0000BB\">Body<\/span><span style=\"color: #007700\">()\u00a0{<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PRINT\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;BODY\u00a0BGCOLOR=\"$this-&gt;bgcol\"\u00a0\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"TEXT=\"$this-&gt;text\"\u00a0\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"LINK=\"$this-&gt;link\"\u00a0VLINK=\"$this-&gt;vlink\"\u00a0\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"ALINK=\"$this-&gt;alink\"&gt;&lt;FONT\u00a0\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"FACE=\"$this-&gt;face\"\u00a0SIZE=$this-&gt;size&gt;n\"<\/span><span style=\"color: #007700\">;<\/p>\n<p>}<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<div class=\"articlePara\">\nThis sets up the page body for us.  It also illustrates a new variable<br \/>\n&#8220;$this.&#8221;  When used inside of a class function it lets the interpreter<br \/>\nknow we are referring to a variable of THIS instance.  In other words,<br \/>\nit&#8217;s assigned the value of the name of the instance in the calling line<br \/>\n(e.g. $this would be == $Basic when $Basic-&gt;Body() is the calling<br \/>\nstatement.)  Also, notice we are doing something here that&#8217;s much<br \/>\nsimpler than is possible in regular functions.  We&#8217;re referring to<br \/>\nvariables that were not passed to the function.  Remember, all functions<br \/>\nand variables of an instance are available to all functions of that<br \/>\ninstance.  To do this with regular functions you&#8217;d have to set up<br \/>\nseveral global arrays.<\/div>\n<div class=\"articlePara\">\nTry this in your php script (assuming you&#8217;ve included the Style class,<br \/>\ncreated the style objects above and sent the &lt;HTML&gt; and &lt;HEAD&gt;&lt;\/HEAD&gt;<br \/>\ntags):<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><br \/>\n<span style=\"color: #0000BB\">&lt;?php\u00a0$Basic<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">Body<\/span><span style=\"color: #007700\">();\u00a0<\/span><span style=\"color: #0000BB\">?&gt;<\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<div class=\"articlePara\">\nNow, we&#8217;re ready to print something out.  We could do it the old<br \/>\nfashioned way, but I&#8217;m going to do something different&#8230; that&#8217;s right<br \/>\nanother function:<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p><\/span><span style=\"color: #007700\">function\u00a0<\/span><span style=\"color: #0000BB\">TextOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$message<\/span><span style=\"color: #007700\">=<\/span><span style=\"color: #DD0000\">\"&amp;nbsp\"<\/span><span style=\"color: #007700\">)\u00a0{<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PRINT\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;FONT\u00a0FACE=\"$this-&gt;face\"\u00a0\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"SIZE=$this-&gt;size\u00a0COLOR=\"$this-&gt;\u00a0\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"text\"&gt;$message&lt;\/FONT&gt;n\"<\/span><span style=\"color: #007700\">;<\/p>\n<p>}<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"rod199906014658.html?page=2\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod19990601.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod199906014658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">3<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod19990601fdb0.html?page=4\">4<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod19990601af4d.html?page=5\">5<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod19990601c575.html?page=6\">6<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"rod19990601fdb0.html?page=4\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The hardest concept I&#8217;ve tried to understand since beginning to use PHP was that of classes. I&#8217;d never used a database engine but learning to use<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1372","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1372"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1372\/revisions"}],"predecessor-version":[{"id":3247,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1372\/revisions\/3247"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}