Results 1 to 4 of 4

Thread: How to use namespaces : fallback to global function in PHP?

  1. #1
    Join Date
    Jun 2009
    Posts
    230

    How to use namespaces : fallback to global function in PHP?

    Hi friends,
    I have just done the namespaces in PHP. I want to make the namespace to fallback to the global. But I don't know how to do that.!! So thought that someone over there will help me by providing the proper solution. I am in total mess now.!! Please explain me how to use namespaces : fallback to global function? Hope that I am clear with my question. Waiting for the replies.!!

  2. #2
    Join Date
    Aug 2006
    Posts
    235

    Re: How to use namespaces : fallback to global function in PHP?

    Since, you have done the Namespaces to some extent, you might know that many times an unresolved warnings are encountered. When PHP encounters a unqualified Name in a class name, function or constant context it gets resolved with the different priorities. A fall back implies more computation which further implies a loss of speed or performance. According to me, you should be mentioned in the document.
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

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

    Re: How to use namespaces : fallback to global function in PHP?

    I got what are you trying to say. In simple words you want to access the global classes inside a namespace which can be done very easily. I have provided you with the coding which does the exact thing :
    PHP Code:
    <?php
    namespace x\y\z;
    class 
    Exception extends \Exception {}

    $x = new Exception('hello'); 
    $y = new \Exception('hello');

    $z = new ArrayObject;
    ?>

  4. #4
    Join Date
    Nov 2008
    Posts
    996

    Re: How to use namespaces : fallback to global function in PHP?

    If a namespaced function or constant does not exist, then the PHP will fall back to global functions or constants. If you want to make the global functions to fallback inside a namespace, then the following example of coding would help you :
    PHP Code:
    <?php
    namespace x\y\z;

    const 
    E_ERROR 45;
    function 
    strlen($str)
    {
        return \
    strlen($str) - 1;
    }

    echo 
    E_ERROR"\n";
    echo 
    INI_ALL"\n";

    echo 
    strlen('hello'), "\n";
    if (
    is_array('hello')) { 
        echo 
    "is array\n";
    } else {
        echo 
    "is not array\n";
    }
    ?>

Similar Threads

  1. Namespaces in C#
    By GOOL in forum Software Development
    Replies: 4
    Last Post: 25-12-2010, 06:03 AM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. How to use namespaces : Aliasing/Importing?
    By Bigga Lexx in forum Software Development
    Replies: 4
    Last Post: 21-02-2010, 04:05 AM
  4. How to Define Namespaces in PHP?
    By SKREECH in forum Software Development
    Replies: 5
    Last Post: 21-02-2010, 02:00 AM
  5. iscsi & multipath fallback
    By steve72 in forum Networking & Security
    Replies: 1
    Last Post: 24-12-2009, 10:24 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,751,892,711.04487 seconds with 16 queries