Activity Stream
48,167 MEMBERS
6712 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 7 of 7
  1.     
    #1
    Member
    Website's:
    epicimagehost.com

    Default [PHP][Help]Redeclare A function

    Right now file-remoter is having a shitload of functions.

    If I want to generate rapidshare remoteable links I called the function:

    $links .= gen_rs_links($links);

    At first I didn't see any harm. The code is cluttered but it's still readable.
    But now I'm supporting 11 hosts.

    Each host has it's own functions ( main function, grab cookies, check links )

    I was rewriting it so I could just do a
    PHP Code: 
    foreach($dlinks as $host => $urls){
      
    $links .= generate_links($host,$urls);

    the function generate_links would be:

    PHP Code: 
    function generate_links($host,$links){
      include(
    '/path/inc/'.$host.'.php');
      return 
    link_gen($links);

    The function link_gen would be unique for every host.

    But apparantly, even in a function. The scope of functions included using the include function is global.

    So I figure that if I have to generate links for multiple hosts, an error will come because I include a function that's already been declared before.

    Any ideas?
    Robin H Reviewed by Robin H on . [PHP]Include functions scope Right now file-remoter is having a shitload of functions. If I want to generate rapidshare remoteable links I called the function: $links .= gen_rs_links($links); At first I didn't see any harm. The code is cluttered but it's still readable. But now I'm supporting 11 hosts. Each host has it's own functions ( main function, grab cookies, check links ) Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    premium-links.net wanted-programs.com
    if functions are messed up, just rename a function and use it!

  4.     
    #3
    Member
    Website's:
    epicimagehost.com
    RaJ, the functions work fine.

    I just need to figure out a way to re-declare functions.
    .. I'll google

    edit:
    Finished googling. Not happy with the results I was getting

  5.     
    #4
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    To be honest you want to place all your methods in a Namespace and then there will be no conflict.

    PHP Code: 
    namespace Functions
    {
        function 
    file_get_contents($path)
        {
            return \
    file_get_contents($path); //the \ is to resolve at the root scope
        
    }


    then use like so:

    PHP Code: 
    $data Functions\file_get_contents($path); 
    This should resolve scope and declaration issues.
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  6.     
    #5
    Member
    how about a switch case , i am learning c++ , but still can understand your php code

  7.     
    #6
    Respected Member
    Have you tried include_once instead of include? It will check if it has been included and not try to include it a second time.

    The only problem with using something like namespace is it limits your code to php 5 servers and up.

  8.     
    #7
    Member
    Website's:
    epicimagehost.com
    Nah,
    I'm just going to fix it with using the API

    PHP Code: 
    foreach($dlinks as $host => $urls){
      
    $links .= generate_links($host,$urls);

    Would become
    PHP Code: 
    foreach($dlinks as $host => $urls){
      
    $post = array();
      
    $post['links'] = implode("\n",$urls);
      
    $post['userID'] = $userID;
      
    $post['host'] = $host;
      
    $links .= getpage('http://api.file-remoter.com/?act=generate',$post);

    I know it's not good practice. But fuck it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. (VB6) Using functions
    By JasonCairns in forum Web Development Area
    Replies: 0
    Last Post: 10th Jan 2012, 01:10 PM
  2. [For Hire] PHP Functions
    By _Vick in forum Completed Transactions
    Replies: 0
    Last Post: 3rd Dec 2011, 10:28 AM
  3. PHP Functions
    By Hydrode in forum General Discussion
    Replies: 3
    Last Post: 7th Feb 2011, 08:05 PM
  4. Scope Hosts - VPS Unmanaged
    By Raven in forum Technical Help Desk Support
    Replies: 11
    Last Post: 19th Jul 2010, 11:26 AM

Tags for this Thread

BE SOCIAL