in Search
     
Latest post 08-06-2007 11:55 PM by modchip. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 08-06-2007 8:52 PM

    • Polie
    • Top 500 Contributor
    • Joined on 08-07-2007
    • Posts 2
    • Points 40

    Enlighten me with function...thank you

    hello guys, im still a newbie when it comes to OOP...

    why the function "salestax" has 2 parameters are they really necessary... thank you very muchBig Smile

    function salestax($price,$tax) {
    $total = $price + ($price * $tax);
    echo "Total cost: $total";
    }

    • Post Points: 20
  • 08-06-2007 9:35 PM In reply to

    • modchip
    • Top 10 Contributor
    • Joined on 02-09-2006
    • Ivalice
    • Posts 710
    • Points 10,110

    Re: Enlighten me with function...thank you

    I'm a n0ob too, but I think they are important. Since it is a function, it can be called from another place, passing different values from it.

    Example:

    function salestax($price,$tax) {
        $total = $price + ($price * $tax);
        echo "Total cost: $total";
    }
    ; some code here...
    salestax(25.00, 0.2) ; Calls the sales tax fuction above.
    ; more code here...
    salestax(27.50, 0.13) ; You can call it again, passing another set of values.
    ; more code here...

    The output would be:

    Total cost: 30 ; from the first call.
    Total cost: 31.075 ; from the second call.

    BTW, I'm not sure, but I think this is not OOP...

    Hope this helps.

    • Post Points: 20
  • 08-06-2007 9:53 PM In reply to

    • Polie
    • Top 500 Contributor
    • Joined on 08-07-2007
    • Posts 2
    • Points 40

    Re: Enlighten me with function...thank you

     thank you modchip Big Smile.. What if i remove the parameter it will still run right? but what will be the negative effect of it? thank you...Drinks

    • Post Points: 20
  • 08-06-2007 10:33 PM In reply to

    • cruizer
    • Top 10 Contributor
    • Joined on 12-14-2005
    • Singapore
    • Posts 944
    • Points 22,590

    Re: Enlighten me with function...thank you

    the parameters are there because THEY ARE NEEDED in order to come up with the desired result. if they're not needed, they shouldn't be there.
    http://devpinoy.org/blogs/cruizer
    Naglalayong buksan at palayain ang kamalayan ng Pinoy .NET developer
    • Post Points: 20
  • 08-06-2007 10:35 PM In reply to

    Re: Enlighten me with function...thank you

    you have to declare a global variable if you don't want the parameters but thats not a good practice... 

    Dwarvend's Review

    • Post Points: 20
  • 08-06-2007 11:55 PM In reply to

    • modchip
    • Top 10 Contributor
    • Joined on 02-09-2006
    • Ivalice
    • Posts 710
    • Points 10,110

    Re: Enlighten me with function...thank you

     As boss cruizer and Dwarvend said, the parameters are needed. It is because the function will be expecting this 2 values. If you think about it, *what will the function compute*?

    • Post Points: 5
Page 1 of 1 (6 items)