Beginner PHP Tutorial – 192 – Changing a Property Value

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

19 responses to “Beginner PHP Tutorial – 192 – Changing a Property Value”

  1. mohsin shaikh Avatar

    Thank you so much, Alex<3.

  2. majestic 07 Avatar

    I'm sorry if this question is stupid, I'm just a beginner. Where did you declare a value of $amount?

  3. R Williams Avatar

    i cant get code when a value has manually been put in by the coder… i need to know how this works with a database.

  4. Quinn Anderson Avatar

    6:51 "we have created a new method called Withdraw" So it's a method and not a function? Part of my research, which has brought me to these videoes (190-192), was to investigate PHP methods and functions…or 'what is the difference between them. i read here http://stackoverflow.com/questions/4841605/what-is-a-difference-between-a-method-and-a-function that "Method is actually a function used in the context of a class/object." Is it incorrect to use the terms interchangeably? Thanks

  5. rohit chakrabarti Avatar

    example for this lesson 🙂
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <style>
    input[type=number]::-webkit-inner-spin-button,
    input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    margin: 0;
    }
    </style>
    </head>
    <body>
    <form action="<?= $_SERVER['PHP_SELF']; ?>" method="POST" name="form">
    <input type="number" name="amount"/>
    <input type="submit" name="submit" value="WITHDRAW"/>
    </form>
    <?php
    if(isset($_POST['amount']) && !empty($_POST['amount'])){
    $amount=$_POST['amount'];
    class BankAccount{
    public $balance=100;
    public function Withdraw($amount) {
    if($this->balance>$amount){
    $this->balance= $this->balance-$amount;
    echo "Withdrwan: ".$amount."<br>";
    return "Balance: ".$this->balance;
    }
    else{
    die("Sorry, insufficient funds");
    }
    }
    }
    $account=new BankAccount;
    echo $account->Withdraw($amount);
    }
    ?>
    </body>
    </html>

  6. Marko Kovacevic Avatar

    Ok, question time. Cant you do this with function Withdraw? function Withdraw($balance, $amount)? // queried result
    $balance = 100;

    function Withdraw($balance, $amount)
    {
    if($amount > $balance)
    {
    return "No enough money";
    }else
    {
    return $balance – $amount;

    }
    }

    echo $alex = Withdraw($balance, 15);
    echo "<br>";
    echo $john = Withdraw($balance, 150);

    Or am i missing something?

  7. Armbreakfire Avatar

    HEADS UP: The tutorials are a bit out of order. After this video, you are going to want to watch 196-198 before continuing to 193.

  8. T S Avatar

    whithdrawwwwwwwwwwwwww

  9. Dwayne Lewis Avatar

    where were the constructor is public function __construct()  mandatory to get data from a class.?

  10. TheEgao Avatar

    nice tutorial, could add a thing about encapsulation 😉

  11. Tuan Anh Ha Avatar

    Thank you for the great Tutorials.

  12. ObscureCoder Avatar

    $newamount = intval($amount);

  13. Yoav Naaman Avatar

    and what if $amount is negative number? like -100000000 ?

  14. Robin Andrews Avatar

    I appreciate the effort you've made, but as this is a tutorial for beginners, and the concepts are new and quite complex from a learners perspective, it would help if you could edit out the mistakes so I can focus on the right way to do things.

  15. TechLearningstudio Avatar

    hey alex, you made this tutorial easy like anything, Nice tutorial 🙂

  16. SmithsRichard Avatar

    lol where it is written that it is pounds? It can be $, euro or rupees

  17. PancakePlease Avatar

    Look, the troll is gone. No dislikes!

  18. MakolEngr Go Avatar

    @bohterham if you mean return $this->balance -= $amount; yes, it is valid and working. the shortcut for return $this->balance = $this->balance – $amount;

  19. bohterham Avatar

    is $this->balance =- $amount; valid?

Leave a Reply

Your email address will not be published. Required fields are marked *