Results 1 to 4 of 4

Thread: Please explain the functionality of given code

  1. #1
    Join Date
    Sep 2009
    Location
    pakistan
    Posts
    28
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Please explain the functionality of given code

    hi friends The following code is working fine , but can anyone explain it plz that how this code is working i mean there is no function call how object employee set title as developer how it calls __set(...). Does this mechanism has any specific name in php.

    class Employee{
    var $name;
    function __set($propName,$propValue){
    $this->$propName = $propValue;
    }
    }
    $employee = new Employee();
    $employee->name = "aqeel";
    $employee->title = "Developer";
    echo "Name : {$employee->name}";
    echo "<br />";
    echo "Title : {$employee->title}";


    The output is
    Name : aqeel
    Title : Developer

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    A class can contain variables. You are just storing values in those variables then echoing them. In fact, I don't think it's even needed (the __set function).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    it's a "magic" method - look here

    however, djr is correct - in this case, the __set() function is doing nothing (or at least, nothing that isn't being done anyway - but, per the page I linked above, I don't think it's doing anything at all). The class variables are being set directly ($employee->name = "aqeel"; $employee->title = "Developer";).

  4. #4
    Join Date
    Sep 2009
    Location
    pakistan
    Posts
    28
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    hay thanks friend , i checked it after commenting function __set(...) thanks with regards aqeel

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •