05132005 1203 GMT-6

Im reading about OOP today and writing my first oop in php. The tutorial 
is a Calculator. Im having some problems with errors.

The Calculator Class:
    <?php
    // the calculator class

        // declare the internal variable
            var $storedValue;
   
        // accessor functions
            function setValue( $passedValue){
                $this->storedValue= $passedValue;
            }

            function getValue(){
                return $this->storedValue;
            }

            function addValue( $passedValue ) {
                $this -> storedValue += $passedValue;
            }


            // constructor function

            function Calculator() {
                $this ->storedValue = 0;
            }

        class Calculator{
            function add ($number1, $number2){
                return $number1 + $number2;
            }

            function subtract($number1, $number2){
                return $number1 - $number2;
            }

            function multiply($number1, $number2){
                return $number1 * $number2;
            }

            function divide($number1, $number2){
                return $number1 / $number2;
            }

        } // end class
    ?>

The HTML Page

<?php
    include ("calculator.php");
?>

<html>
    <head>
        <title>Try it out - Calculator Memory</title>
    </head>

    <body>
        <?php
            $valueToStore = 10;
            echo "The value to be stored is $valueToStore<br />";

            $myCalculator = new calculator();

            $myCalculator -> setValue($valueToStore);
            $restoredValue = $myCalculator->getValue();
            echo "The value returned is $restoredValue<br />";
        ?>
    </body>
</html>

The error Im getting is:
    *Parse error*: syntax error, unexpected T_VAR in *C:\WebDev\Work 
Directory\Beg_PHP4\CH9\calculator.php* on line *5
*
That line is var $storedValue;

So, I get that $storedValue is a variable that is only accessiable 
inside the class. But Im totaly unclear as to some of these variables.

Like on the function setValue($passedValue). Shouldnt that be named 
$valueToStore? And what about $storedValue?

Im just not seeing how these are passed around.

Wade


[Non-text portions of this message have been removed]



Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to