Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-27-2011, 12:10 PM   PM User | #1
bngari
New Coder

 
Join Date: Nov 2010
Location: Kenya
Posts: 38
Thanks: 3
Thanked 1 Time in 1 Post
bngari is an unknown quantity at this point
PHP array error

Hi, a website i'm working on is having a problem. It is giving an error like
PHP Code:
WarningParameter 2 to frontpage() expected to be a referencevalue given in /usr/www/users/netwas/includes/Cache/Lite/Function.php  on line 101 
what can I do to rectify it? website address is http://netwas.org. Hlp will be appreciated.
__________________
Write an Essay, Get all your best web articles.
bngari is offline   Reply With Quote
Old 05-27-2011, 12:12 PM   PM User | #2
tomharto
Regular Coder

 
Join Date: Jul 2010
Location: Sheffield
Posts: 796
Thanks: 91
Thanked 18 Times in 18 Posts
tomharto is on a distinguished road
What the code causing the error? Line 101 on Functions.php
tomharto is offline   Reply With Quote
Old 05-27-2011, 12:56 PM   PM User | #3
bngari
New Coder

 
Join Date: Nov 2010
Location: Kenya
Posts: 38
Thanks: 3
Thanked 1 Time in 1 Post
bngari is an unknown quantity at this point
PHP Code:
<?php

/**
* This class extends Cache_Lite and can be used to cache the result and output of functions/methods
*
* This class is completly inspired from Sebastian Bergmann's
* PEAR/Cache_Function class. This is only an adaptation to
* Cache_Lite
*
* There are some examples in the 'docs/examples' file
* Technical choices are described in the 'docs/technical' file
*
* @package Cache_Lite
* @version $Id: Function.php 49 2005-09-15 02:55:27Z rhuk $
* @author Sebastian BERGMANN <sb@sebastian-bergmann.de>
* @author Fabien MARTY <fab@php.net>
*/

// no direct access
defined'_VALID_MOS' ) or die( 'Restricted access' );

require_once( 
$mosConfig_absolute_path '/includes/Cache/Lite.php' );

class 
Cache_Lite_Function extends Cache_Lite
{

    
// --- Private properties ---

    /**
    * Default cache group for function caching
    *
    * @var string $_defaultGroup
    */
    
var $_defaultGroup 'Cache_Lite_Function';

    
// --- Public methods ----

    /**
    * Constructor
    *
    * $options is an assoc. To have a look at availables options,
    * see the constructor of the Cache_Lite class in 'Cache_Lite.php'
    *
    * Comparing to Cache_Lite constructor, there is another option :
    * $options = array(
    *     (...) see Cache_Lite constructor
    *     'defaultGroup' => default cache group for function caching (string)
    * );
    *
    * @param array $options options
    * @access public
    */
    
function Cache_Lite_Function($options = array(NULL))
    {
        if (isset(
$options['defaultGroup'])) {
            
$this->_defaultGroup $options['defaultGroup'];
        }
        
$this->Cache_Lite($options);
    }

    
/**
    * Calls a cacheable function or method (or not if there is already a cache for it)
    *
    * Arguments of this method are read with func_get_args. So it doesn't appear
    * in the function definition. Synopsis :
    * call('functionName', $arg1, $arg2, ...)
    * (arg1, arg2... are arguments of 'functionName')
    *
    * @return mixed result of the function/method
    * @access public
    */
    
function call()
    {
        
$arguments func_get_args();
        
$id serialize($arguments); // Generate a cache id
        
if (!$this->_fileNameProtection) {
            
$id md5($id);
            
// if fileNameProtection is set to false, then the id has to be hashed
            // because it's a very bad file name in most cases
        
}
        
$data $this->get($id$this->_defaultGroup);
        if (
$data !== false) {
            
$array unserialize($data);
            
$output $array['output'];
            
$result $array['result'];
        } else {
            
ob_start();
            
ob_implicit_flush(false);
            
$target array_shift($arguments);
            
$argu $target;
            if (
strstr($target'::')) { // classname::staticMethod
                
list($class$method) = explode('::'$target);
                
$result call_user_func_array(array($class$method), $arguments);
            } else if (
strstr($target'->')) { // object->method
                // use a stupid name ($objet_123456789 because) of problems when the object
                // name is the same as this var name
                
list($object_123456789$method) = explode('->'$target);
                global $
$object_123456789;
                
$result call_user_func_array(array($$object_123456789$method), $arguments);
            } else { 
// function
                
$result call_user_func_array($target$arguments);
            }
            
$output ob_get_contents();
            
ob_end_clean();
            
$array['output'] = $output;
            
$array['result'] = $result;
            
$this->save(serialize($array), $id$this->_defaultGroup);
        }
        echo(
$output);
        return 
$result;
    }

}

?>
__________________
Write an Essay, Get all your best web articles.
bngari is offline   Reply With Quote
Old 05-27-2011, 02:32 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If this script is function.php, then you cannot do what you are doing.
Call_user_func[_array] cannot be used to pass referenced values to a function (line 101). func_get_args are also non-referenced. You must explicitly call this frontpage() function or modify it to accept a non-referenced variable and return a result.

Edit:
Depending what it does, you can promote to a 5.0+ class object, and use interfacing to achieve control on an Interfaced object type instead.

Last edited by Fou-Lu; 05-27-2011 at 02:35 PM..
Fou-Lu is offline   Reply With Quote
Old 05-29-2011, 09:01 AM   PM User | #5
bngari
New Coder

 
Join Date: Nov 2010
Location: Kenya
Posts: 38
Thanks: 3
Thanked 1 Time in 1 Post
bngari is an unknown quantity at this point
The file is in a CMS website
__________________
Write an Essay, Get all your best web articles.
bngari is offline   Reply With Quote
Old 05-29-2011, 04:34 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I don't care what its for, what I meant is what each of the class or objects are supposed to do.
What I'm saying is you cannot do this:
PHP Code:
class Test
{
    public static function 
dotest(&$var)
    {
        
$var .= ', ' $var;
    }
}

$var 'test';
call_user_func(array('Test''dotest'), $var); 
As that will trigger a reference warning. call_user_func[_array] cannot be used to pass-by-reference parameters.

What needs to happen is either a common interface is implemented to every provided object so that it can force an invocation, or you can use reflection to generate this as well:
PHP Code:

class Test
{
    public 
$var;
    public static function 
dostatictest(&$var)
    {
        
$var $var ', ' $var;
    }
    public function 
dotest(&$var)
    {
        
$this->var $var .= ', ' $var;
    }
}

$var 'static ok';
$rm1 = new ReflectionMethod('Test''dostatictest');
$rm1->invokeArgs(null, array(&$var));
print 
$var PHP_EOL;
$var 'dynamic ok';
$obj = new Test();
$rm2 = new ReflectionMethod('Test''dotest');
$rm2->invokeArgs($obj, array(&$var));
print 
'var: ' $var PHP_EOL;
print 
'member: ' $obj->var PHP_EOL
invokeArgs must be used; invoke will trigger a deprecation notice against the call-time pass-by-reference. I don't know if this is an oversight on the zend team, or if its a feature that will continue allowing us call-time pass-by-reference against the reflection's invoke.

Also note that this will work:
PHP Code:
$var 'call';
call_user_func_array(array('Test''dostatictest'), array(&$var));
print 
'call: ' $var PHP_EOL
without triggering a notice, but it is explicitly stated by the api to be deprecated (and makes note of the failure to trigger a notice): http://php.ca/manual/en/function.cal...nc-array-notes. This is the reason why I cannot be sure that the invokeArgs is working as intended, even though there is no reference to an untriggered deprecation notice. This is why I would personally take an interface approach so I can be guaranteed of specific methods availability on an object. I don't believe this would work with static calls though, but I have never tried that.
Fou-Lu is offline   Reply With Quote
Old 06-02-2011, 07:53 AM   PM User | #7
bngari
New Coder

 
Join Date: Nov 2010
Location: Kenya
Posts: 38
Thanks: 3
Thanked 1 Time in 1 Post
bngari is an unknown quantity at this point
Thanks for the help but the code logic is okay. The problem was caused by an upgrade of the php version from 5.2 to 5.3. A few lines of extra code solved the issue. Cheers
__________________
Write an Essay, Get all your best web articles.
bngari is offline   Reply With Quote
Reply

Bookmarks

Tags
array, joomla, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:33 AM.


Advertisement
Log in to turn off these ads.