iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Programming Programmers can seek advice or just show off their creations inside this forum.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2009, 10:27 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,707
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Lightbulb PHP 6 on the radar.

The latest stable version of php is PHP 5.3.0: PHP: Downloads

The publication date of PHP 6 is coming closer: PHP Sources Snapshots

and the following book PHP 6.0 book will Publish Sept 2009 "PHP 6 for Absolute Beginners" by Jason Lengstor:

Note that PHP is a loosely type language with its pro and cons.

Exercise: Predict the outcome of this

listing03.07.php
PHP Code:
<?php
require_once( "listing03.10.php" );

class 
ShopProductWriter {
    public function 
writeShopProduct $shopProduct ) {
        
$str  "{$shopProduct->title}: ";   
        
$str .= $shopProduct->getProducer();
        
$str .= " ({$shopProduct->price})\n";
        print 
$str;
    }
}
class 
Wrong { }
$product1 = new ShopProduct"My Antonia""Willa""Cather"5.99 );
$writer = new ShopProductWriter();
$wrong  = new Wrong();
// $writer->write( $product1 );
$writer->write$wrong );

?>
Where:
listing03.10.php
PHP Code:
<?php
class CdProduct {
    public 
$playLength;
    public 
$title;
    public 
$producerMainName;
    public 
$producerFirstName;
    public 
$price;

    function 
__construct(   $title$firstName
                            
$mainName$price
                            
$playLength ) { 
        
$this->title             $title;
        
$this->producerFirstName $firstName;
        
$this->producerMainName  $mainName;
        
$this->price             $price;
        
$this->playLength        $playLength;

    }

    function 
getPlayLength() {
        return 
$this->playLength;
    }

    function 
getSummaryLine() {
        
$base  "$this->title ( $this->producerMainName, ";
        
$base .= "$this->producerFirstName )"
        
$base .= ": playing time - $this->playLength";
        return 
$base;
    }

    function 
getProducer() {
        return 
"{$this->producerFirstName}".
               
" {$this->producerMainName}";
    }
}

class 
BookProduct {
    public 
$numPages;
    public 
$title;
    public 
$producerMainName;
    public 
$producerFirstName;
    public 
$price;

    function 
__construct(   $title$firstName
                            
$mainName$price
                            
$numPages ) { 
        
$this->title             $title;
        
$this->producerFirstName $firstName;
        
$this->producerMainName  $mainName;
        
$this->price             $price;
        
$this->numPages          $numPages;
    }
 
    function 
getNumberOfPages() {
        return 
$this->numPages;
    }

    function 
getSummaryLine() {
        
$base  "$this->title ( $this->producerMainName, ";
        
$base .= "$this->producerFirstName )"
        
$base .= ": page count - $this->numPages";
        return 
$base;
    }

    function 
getProducer() {
        return 
"{$this->producerFirstName}".
               
" {$this->producerMainName}";
    }

}

$product1 = new BookProduct(    "My Antonia""Willa""Cather"5.99300 );
$product2 =   new CdProduct(    "Exile on Coldharbour Lane"
                                
"The""Alabama 3"10.9960.33 );

print 
"author:          ".$product1->getProducer()."\n";
print 
"number of pages: ".$product1->getNumberOfPages()."\n";
print 
"summary:         ".$product1->getSummaryLine()."\n";
print 
"artist:          ".$product2->getProducer()."\n";
print 
"play length:     ".$product2->getPlayLength()."\n";
print 
"summary:         ".$product2->getSummaryLine()."\n";
?>
Note the definition of the constructor function in PHP 5 versus version 4 where the constructor function took the same name as the class.

PHP Code:
function __construct(   $title$firstName
                            
$mainName$price
                            
$playLength ) { 
        
$this->title             $title;
        
$this->producerFirstName $firstName;
        
$this->producerMainName  $mainName;
        
$this->price             $price;
        
$this->playLength        $playLength;

    } 
code before you see the result here:

http://www.kjellbleivik.com/Books/PH...sting03.07.php

Source: APRESS.COM : PHP 5 Objects, Patterns, and Practice : 9781590593806

For those that want to develop their own CMS or shopping chart from scratch, I draw your attention to those two books:

Build Your Own Database Driven Web Site Using PHP & MySQL, 4th edition by Kevin Yank (Exercise for the student. Rewrite the code examples using

PHP patterns and classes if that is possible)

and

Simply SQL by Rudy Limeback

KW search:

class type

php class type

Related: Class type hints (Note this is security related.)

"Although PHP remains a loosely typed language, which means you do not need to specify what types a variable is when it is declared or passed to a function, PHP 5 introduced class type hints, which allow you to specify what kind of class should be passed into a function. These are not required, and are also not checked until the script is actually run, so they aren't strict by any means.
Furthermore, they only work for classes right now - you can't specify, for example, that a parameter should be an integer or a string. Having said that, I suspect future versions may introduce the ability to request that arrays are passed in - that's pure speculation, though! (Edit: this was subsequently added in PHP 5.1 - hurrah!)"

and

"But after a while, most programmers realize that this means that a program is equipped with a safety net: many errors that programmers make when they construct programs are caught by this net before they lead to unpleasant effects. An example: A very expensive American space rocket crashed on its way to Venus a few years ago, because of an extremely trivial error in a FORTRAN program. A comma had be written as a point, and, as a consequence of that, the start of a special kind of repeat imperative was mistakenly read as an assignment imperative assigning a value to an undeclared variable. Had it been required to declare every variable in FORTRAN programs, the compiler would have discovered that the variable was undeclared and the error would have been caught much earlier than in the Atlantic Ocean."
Professor Bjørn Kirkerud (1989): "Object Oriented Programming With Simula". Addison Wesley Publishing Company ISBN 0 201 17574 6. Page 31-32.


Related php.net links:

gettype

isset

Last edited by kgun; 07-30-2009 at 11:37 AM.
Reply With Quote
  #2 (permalink)  
Old 09-23-2009, 02:10 PM
WebProWorld Member
 
Join Date: Sep 2009
Posts: 26
mimos RepRank 2mimos RepRank 2
Default Re: PHP 6 on the radar.

I got this: Fatal error: Class 'ShopProduct' not found in /usr/home/web/wno134614/Books/PHP5Obj/03/listing03.07.php on line 13
__________________
free ebooks
Reply With Quote
  #3 (permalink)  
Old 09-23-2009, 04:54 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,707
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: PHP 6 on the radar.

Very late response (one reason that I may stop these posts), but as far as I remember it is correct that you shall get that error. Note there is output before the error occurs.

Last edited by kgun; 09-23-2009 at 04:57 PM.
Reply With Quote
Reply

  WebProWorld > Computer Assistance > Programming

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New site: Coast Radar ibarnes Submit Your Site For Review 2 05-19-2009 07:31 PM
Getting On The Google Radar ronmauldin Google Discussion Forum 14 06-06-2005 08:40 PM
Bangalore appears on terror radar WPW_Feedbot IT Discussion Forum 0 03-07-2005 01:30 PM
Zafi.D upgraded to Radar Level 2 WPW_Feedbot IT Discussion Forum 0 12-14-2004 11:50 AM
Radar Detectors / Auto site reppy Marketing Strategies Discussion Forum 0 10-27-2004 02:33 AM


All times are GMT -4. The time now is 07:18 AM.



Search Engine Optimization by vBSEO 3.3.0