Results 1 to 5 of 5

Thread: How to Return and Unset the References in PHP?

  1. #1
    Join Date
    Jul 2006
    Posts
    218

    How to Return and Unset the References in PHP?

    Hello friends,
    I have done some basic coding in PHP and I am not an expert in that. I need some help from you guys like you always do.!! Recently I have started with the topic of references. I have got some points of references. But now I told to do the unset and I have to return the references which I don't know how to do.!! Please tell me how to Return and Unset the References in PHP? Hoping that someone would reply soon.!!
    ~*~Silent~Kid~*~
    "To The World You May Be Just One Person, But To One Person You May Be The World"

  2. #2
    Join Date
    Mar 2008
    Posts
    349

    Re: How to Return and Unset the References in PHP?

    I think that before returning and unsetting the references, you should know more about the references which is important. As its name implies, a reference in PHP is a variable that "references" the contents of another variable. By using references, you can refer or point to the same data using different variables. When you trigger an exception, normally the following things are occurred.
    • The code which is running currently is saved.
    • The code execution will switch to a predefined exception handler function.
    • Handler may then resume the execution from the saved code state, terminate the script execution or continue the script from a different location in the code and this all depends on the situation.

  3. #3
    Join Date
    Mar 2008
    Posts
    672

    Re: How to Return and Unset the References in PHP?

    As usual you will have to write an exception in try and catch block. So that when an exception is thrown, the code following it will not be executed, and PHP will try to find the matching catch block. The following example has a proper code :
    PHP Code:
    <?php
    function CheckDemo($number)
      {
      if(
    $number>5)
        {
        throw new 
    Exception("Value must be 5 or below");
        }
      return 
    true;
      }

    try
      {
      
    checkNum(2);
      echo 
    'If you see this, the number is 5 or below';
      }

    catch(
    Exception $e)
      {
      echo 
    'Message: ' .$e->getMessage();
      }
    ?>

  4. #4
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to Return and Unset the References in PHP?

    When you want to use a function to find to which variable a reference should be bound then the returning by reference is useful. the main thing that you should keep in mind that not to use the return-by-reference to increase performance. Because the engine will automatically optimize this on its own. The following is an syntax to return references :
    PHP Code:
    <?php
    class call {
        public 
    $value 52;

        public function &
    getValue() {
            return 
    $this->value;
        }
    }

    $obj = new call;
    $myValue = &$obj->getValue();
    $obj->valuewhich is 52.
    $obj
    ->value 2;
    echo 
    $myValue;                
    ?>

  5. #5
    Join Date
    Nov 2008
    Posts
    996

    Re: How to Return and Unset the References in PHP?

    When you want to unset the reference, you can do it just by breaking the binding between variable name and variable content. you have not to worry about because by doing this variable content will not be destroyed. I have provided an example that explains the same :
    PHP Code:
    <?php
    $a 
    3;
    $b =& $a;
    unset(
    $a); 
    ?>
    The above coding won't unset $b, just $a.

Similar Threads

  1. Delete Printer References In the registry
    By Victor Kam in forum Windows XP Support
    Replies: 3
    Last Post: 26-07-2011, 02:13 PM
  2. Replies: 4
    Last Post: 20-01-2011, 11:14 AM
  3. What are the References in PHP?
    By Flaco in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 03:19 AM
  4. How to build cross references in a database
    By Thunder Chicken in forum Software Development
    Replies: 4
    Last Post: 07-11-2009, 07:20 PM
  5. Unset Read Only For My Documents in Xp Home
    By zaid in forum Operating Systems
    Replies: 3
    Last Post: 17-08-2009, 03:06 PM

Tags for this Thread

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
  •  
Page generated in 1,750,583,351.71901 seconds with 16 queries