We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

the define function with namespace

I have a simple php library that i am using, now i wnat to upgrade it. I want to create namespace on it so my class will be inside on the namespaces bu t i got an error when i i tried to use namespace.

here a sample

<?php
    defined('protect')||(header("HTTP/1.0 404 Not Found"));

    require_once 'conf/configuration.php';
    class string{
        function __construct(){
            //some code;
        }

        //some function;
    }
    ?>

I used the defined function to protect the php file for direct accesss.
Now when i used namespace the code look like this.

<?php
    defined('protect')||(header("HTTP/1.0 404 Not Found"));
    namespace teststring;
    {
    require_once 'conf/configuration.php';
    class string{
        function __construct(){
            //some code;
        }

        //some function;
    }
    }
    ?>

now it will get an error surely because the namespace should be on the very first line. but when i put the defined function inside the namespace i think it cant protect the file from direct access, i already googled this but so far i got no good results.

i am asking how to protect my php files from direct access when i am using namespace?

I will appreciate for any help will come. thanks

btw sorry for my bad english

2
Contributors
2
Replies
1 Hour
Discussion Span
7 Months Ago
Last Updated
3
Views
Question
Answered
ZER09
Junior Poster in Training
74 posts since Jul 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

You can access globals with the backslash inside namespaces:

echo \protect;
diafol
Keep Smiling
Moderator
10,842 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,536
Skill Endorsements: 61

thanks it solve

ZER09
Junior Poster in Training
74 posts since Jul 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 7 Months Ago by diafol

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0672 seconds using 2.73MB