SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2007
    Location
    London
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up call_user_func() alternative help

    ah, hello...
    I've got a file taken from part of a forum script which was built for earlier versions of php and i keep getting
    Code:
    Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of call_user_func(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in /home/n4/gvs/se314/forum.php on line 265
    I haven't got access to php.ini on this server and even if i did i doubt i'd want to turn it on anyway... I'm not sure how the function even works. My understanding is that it calls other functions and passes a value or values to it...The php error says to modify the declaration but i'm clueless. The whole page is included below... Can anyone help with a re-write of the call_user_func() bit?

    PHP Code:
    <?        
    error_reporting
    (0);
    // dispatcher
    ini_set('display_errors'1);
    ini_set('allow_call_time_pass_reference'1);
    error_reporting(E_ALL);

    define('SE_PAGE'true);

    include 
    "header.php";
    include_once 
    "header_forum.php"// make sure forum header is loaded, even plugin is disabled

    // @INFO: interface
    // $language_code = en|de|...
    if(SEP_Forum_SE_Version == 3) {
        
    $_language SE_Language::info();
        
    $language_code $_language['language_code'];
    }
    else {
        
    $language_code $languages_map_v2[$global_lang];
    }

    $SEPFLG->init(getcwd().'/locale''forum'$language_code);


    if(
    $url_style == 'mod_rewrite') {
        
    $_url_base SEP_Forum_Models::get_forum_setting('url_base');
        if(
    substr($_url_base, -1) != '/') {
            
    $_url_base .= '/';
        }
        
    $url->url_base $_url_base;
        unset(
    $_url_base);


        
    /*
         * Delegate Controller/Action with mod_rewrite query
         *
         * Possible routes:
         *
         * Forum Controller
         *         /forum[/instance_id][/action][/category_id][/page]
         *         PARAMS: instance_id, action, category_id, page
         *
         * Category Controller:
         *         /forum[/instance_id]/category/category_id[/action][/topic_id][/page]
         *         PARAMS: instance_id, category_id, action, topic_id, page
         *
         * Topic Controller:
         *         /forum[/instance_id]/topic/category_id/action/topic_id[/page][#jump_to_post_id]
         *         PARAMS: instance_id, category_id, action, topic_id, page
         *
         * Post Controller:
         *         /forum[/instance_id]/post/category_id/action/post_id
         *         PARAMS: instance_id, category_id, action, post_id
         *
         * Attachment Controller:
         *         /forum[/instance_id]/attachment/category_id/post_id/attachment_id
         *         PARAMS: instance_id, category_id, post_id, attachment_id
         *
         * SEO URL (redirects to topic controller with topic_id and page)
         *         /forum/category/sub_category/title-topic_id-page.html
         *
         */
        
    $category_id     null;
        
    $topic_id         null;
        
    $post_id         null;
        
    $attachment_id    null;
        
    $action         null;
        
    $controller        null;

        
    $_forum_controller_actions = array('bookmarks''browse''subindex''index''my_posts''search''settings');
        
    $_controllers = array('category''topic''post''attachment'); // except for forum

        
    $requested_uri array_slice(explode('/'strip_tags($_SERVER['REQUEST_URI'])), 2);

        
    // parse requested_uri...
        
    $req_uri_part array_shift($requested_uri);
        if(!empty(
    $req_uri_part)) {

            if(
    is_numeric($req_uri_part)) {
                
    $instance_id $req_uri_part;
                unset(
    $req_uri_part);$req_uri_part = @array_shift($requested_uri);
            }

            if(
    in_array($req_uri_part$_forum_controller_actions)) {
                
    // forum controller
                
    $controller 'forum';
                
    $action $req_uri_part;
                
    $category_id = @array_shift($requested_uri);
                
    $page_id = @array_shift($requested_uri);
            }
            elseif(
    in_array($req_uri_part$_controllers)) {
                
    // other controller
                
    $controller $req_uri_part;
                
    $category_id = @array_shift($requested_uri);
                
    $action = @array_shift($requested_uri);

                if(
    $controller == 'post') {
                    
    $post_id = @array_shift($requested_uri);
                }
                elseif(
    $controller == 'attachment') {
                    
    $post_id $action;
                    
    $action 'download';
                    
    $attachment_id = @array_shift($requested_uri);
                }
                else {
                    
    $topic_id = @array_shift($requested_uri);
                    
    $page_id = @array_shift($requested_uri);
                }
            }

            if(empty(
    $controller)) {
                
    // SEO url?
                // get topic_id and page_id
                
    $matches = array();
                
    preg_match("/([0-9]*?)\-([0-9]*?)\.html$/"$requested_uri[1], $matches);

                if(!empty(
    $matches[1]) && !empty($matches[2])) {
                    
    $topic_id $matches[1];
                    
    $page_id $matches[2];

                    
    // get category_id and instance_id
                    
    $_post_item $SEPFSQL->find('first', array('model' => 'Post''fields' => array('id''instance_id''category_id'),
                                                                
    'conditions' => array('Post.id=?', array($topic_id))));

                    if(!empty(
    $_post_item['Post']['id'])) {
                        
    $instance_id $_post_item['Post']['instance_id'];
                        
    $category_id $_post_item['Post']['category_id'];

                        
    $controller 'topic';
                        
    $action 'index';
                    }
                }
            }
        }

        if(empty(
    $controller)) {
            
    $controller 'forum';
        }

        if(empty(
    $action)) {
            
    $action 'index';
        }

        
    $params = array('params' => array('instance_id' => $instance_id,
                                              
    'category_id' => $category_id,
                                              
    'topic_id'    => $topic_id,
                                             
    'post_id' => $post_id,
                                              
    'page'        => $page_id,
                                             
    'attachment_id' => $attachment_id,
                                             
    'action' => $action,
                                               
    'controller' => $controller));

        
    // add raw requested uri to params
        
    $params['requested_uri'] = $requested_uri;

    }
    else {
        
    /*
         * Delegate Controller/Action with normal url query
         *
         * $controller = [category|topic|post|attachment] (becomes 'forum' if empty)
         *
         */
        
    $instance_id     $multi_instances && !empty($_GET['iid']) ? $_GET['iid'] : $instance_id;
        
    $category_id     = !empty($_GET['cid']) ? $_GET['cid'] : null;
        
    $topic_id         = !empty($_GET['tid']) ? $_GET['tid'] : null;
        
    $post_id         = !empty($_GET['pid']) ? $_GET['pid'] : null;
        
    $page_id         = !empty($_GET['page']) ? $_GET['page'] : null;
        
    $attachment_id    = !empty($_GET['aid']) ? $_GET['aid'] : null;
        
    $action         = !empty($_GET['op']) ? $_GET['op'] : 'browse';
        
    $controller        = !empty($_GET['c']) ? $_GET['c'] : 'forum';


        
    $params = array('params' => array('instance_id' => $instance_id,
                                            
    'category_id' => $category_id,
                                            
    'topic_id' => $topic_id,
                                            
    'post_id' => $post_id,
                                            
    'page' => $page_id,
                                            
    'attachment_id' => $attachment_id,
                                            
    'action' => $action,
                                            
    'controller' => $controller));

    }

    // Comment out for debugging!
    //echo "<hr>CONTROLLER: $controller<br>";
    //echo "ACTION: $action<br>";
    //echo "INSTANCE_ID: $instance_id<br>";
    //echo "CATEGORY_ID: $category_id<br>";
    //echo "TOPIC_ID: $topic_id<br>";
    //echo "POST_ID: $post_id<br>";
    //echo "PAGE: $page_id<br>";
    //echo "ATTACHMENT_ID: $attachment_id<br>";
    //exit;


    // clean controller
    $controller strtolower(preg_replace('/[^a-z0-9]/i'''$controller));

    // URL Helper Init
    $SEPFURL->init($multi_instances$instance_id$url_style);

    // Prepare user object
    $params['user']['_object'] = $user;
    $params['user']['logged_in'] = !empty($user->user_info[user_id]) ? true false;
    $params['user']['id'] = $user->user_info[user_id];
    $params['user']['photo'] = $user->user_info[user_photo];
    $params['user']['name'] = $user->user_info[user_username];
    $params['user']['display_name'] = !empty($user->user_displayname) ? $user->user_displayname $user->user_info[user_username];
    $params['user']['email'] = $user->user_info[user_email];
    $params['user']['level_id'] = $user->user_info[user_level_id];
    $params['user']['subnet_id'] = $user->user_info[user_subnet_id];
    $params['user']['profilecat_id'] = $user->user_info[user_profilecat_id];

    // Assign user object
    $smarty->assign('sep_forum_user'$params['user']);
    $smarty->assign('_active_tab''');


    if(
    $params['params']['controller'] == 'forum' && in_array($params['params']['action'], array('index''browse')) && empty($params['params']['instance_id'])) {
        
    $params['params']['instance_id'] = $global_instance_id;
    }


    // check if there are any instances for forum?
    $show_header_and_footer true;
    if(
    $SEPFSQL->find('count', array('model' => 'Instance''conditions' => array('mode=?', array('forum')), 'limit' => 1)) == 0) {
        
    SEP_Forum_Helper::redirect_to_error('There are no forums to access.');
        exit;
    }
    else {
        if(
    $multi_instances) {
            
    // check if this instance is a forum or a group
            
    $_instance_info $SEPFSQL->find('first', array('model' => 'Instance''fields' => array('mode'), 'conditions' => array('id=?', array($params['params']['instance_id']))));
            if(
    $_instance_info['Instance']['mode'] == 'group') {
                
    $show_header_and_footer false;
            }
        }
    }
    $smarty->assign('show_header_and_footer'$show_header_and_footer);

    /*
     * Delegate controller/actions and pass params to action
     */
    // whitelisting available controllers
    if(!in_array($controller, array('category''forum''post''topic''attachment'))) {
        
    SEP_Forum_Helper::redirect_to_error('Invalid url request');
        exit;
    }

    $lk=SEP_Forum_Models::get_forum_setting("license_key");if(empty($lk)){SEP_Forum_Helper::redirect_to_error("The forum is not available at the moment. No license key found.");}


    function 
    dummy() {}
    $plugin_disabled false;
    $plugin_disabled = @mysql_query("SELECT 1 FROM se_plugins WHERE plugin_type='forum' AND plugin_disabled=1 LIMIT 1") OR dummy();
    $plugin_disabled = @mysql_fetch_row($plugin_disabled);
    if(
    $plugin_disabled) {
        
    SEP_Forum_Helper::redirect_to_error('The forum is not available at the moment');
        exit;    
    }

    require 
    getcwd().'/include/forum/controllers/'.$controller.'_controller.php';
    call_user_func(array('SEP_'.ucfirst($controller).'Controller'$action), &$params, &$SEPFSQL, &$SEPFLG, &$SEPFURL, &$smarty);



    if(empty(
    $params['layout'])) {
        
    $page 'forum/'.$controller.'_'.$action;
    }
    else {
        
    $page 'forum/'.$params['layout'];
    }


    // Flash messages
    $smarty->assign('sep_flash_error'SEP_Forum_Helper::getFlash('error'));
    $smarty->assign('sep_flash_success'SEP_Forum_Helper::getFlash('success'));
    $smarty->assign('sep_flash_info'SEP_Forum_Helper::getFlash('info'));
    SEP_Forum_Helper::resetFlash();



    include 
    "footer.php";


    ?>
    thanks for any help. Of course if there is something obvious that i can use as a work around you can point this out to me i'm not asking for someone to do my coding for my i just don;t follow this bit at all...
    thank you..

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Removing the ampersands before the variables names will safely get rid of your errors as long as you're using php5. The only questionable one is the $params variable, because it is not an object(ojects are automatically passed by reference now). If some code expects that array to get modified after that method is called, then removing the ampersand may change the behavior of the code.

    You could also just use the stfu operator @ and silence the error. But php is trying to tell you that one day soon it might not work anymore.

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    just use the stfu operator @
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2007
    Location
    London
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep removing the ampersands got rid of the errors and i did try using @ before but it never silenced it... if you or anyone else could, can you explain what is happening in that line please?

    PHP Code:
    call_user_func(array('SEP_'.ucfirst($controller).'Controller'$action), &$params, &$SEPFSQL, &$SEPFLG, &$SEPFURL, &$smarty); 
    I know php is tryna say one day it might not work so if i had a better understanding at what was going on there i would slowly re-write to something that works and that i understand...

    the errors are gone now though so thanks for the speedy response...

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's calling a method of a class. Once you expand the variables you get the equivalent of
    PHP Code:
    SEP_AttachmentController::download(&$params, &$SEPFSQL, &$SEPFLG, &$SEPFURL, &$smarty);
    // or
    SEP_ForumController::search(&$params, &$SEPFSQL, &$SEPFLG, &$SEPFURL, &$smarty); 
    To over simplify, its calling a function.

    As far as references, see http://www.php.net/references

  6. #6
    SitePoint Member
    Join Date
    May 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    You could also just use the stfu operator @ and silence the error. But php is trying to tell you that one day soon it might not work anymore.
    except that it's extremely costly to use.. very slow, I've even seen some pundits advising against it..

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2007
    Location
    London
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm not using it. It never got rid of the errors. What i did was removed the ampersands and the errors went but as predicted before by crmalibu some stuff started going a bit nutts and wouldn't work. I'm moving the whole site over to a dedicated server soon so i'll be able to turn the option on. I'll have to have the forum section re-coded to avoid using references.

  8. #8
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by saidus View Post
    except that it's extremely costly to use.. very slow, I've even seen some pundits advising against it..
    The real cost comes in debugging. If something is broken you expect some type of error. If you've turned that off in one line in one of dozens of possible files it will be rather difficult to track down.


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
  •