Deployed application to production and running into the following error on views that contain a call to a render function:
Fatal error: No matching function for overloaded 'render'
Example
/fuel/app/views/profile.php:
echo render('_validation');
Render is defined in /fuel/core/classes/view.php. The Autoloader should be making this available.
Ideas on environmental issues that may be causing this?
Edit: Both APPPATH and COREPATH hold the correct file paths
Try to use more clear function names, so you won't get in trouble with standart PHP functions.
It looks like your render-function is declared inside a class, if it is so you have to initialize an object of that class or use an existing object to call the method
echo $object->render('_validation');
Unsure if it is an issue specific with 5.3.3 but we just changed render() to View::forge() across the applications and all is well.
Related
I am using this script http://fpdf.org/en/script/script50.php and I am getting the error:
Fatal error: Call to undefined method PDF::FPDF() in MyPath/html_table.php on line 55
it is this call to FPDF that is throwing the exception :
$this->FPDF($orientation,$unit,$format);
I don't understand why, knowing that the pdf class extends FPDF and I have the fpdf.php file in the same directory as the html_table.php file, is there any way to fix this error? Thank you
Fixed it.
I actually needed to replace :
$this->FPDF($orientation,$unit,$format);
by:
$this->__construct($orientation,$unit,$format);
The original script has this error, so for anyone wanting to use the script don't forget to fix this error first. Good luck.
I can't find $this->FPDF anywhere in the script you shared. When you extend a class, the extended class is in the $this of the class you extended it with.
The constructor of the extended class will always be ran when you create a new instance of this class unless you define a constructor yourself, which you did in the PDF-class as the script you shared shows.
If you want to run the constructor of the class you extended, you should do this from within the contructor of the extending class using parent::__construct(); which tells PHP that it should at that moment run the contructor of the parent class (the extended class).
This is already the case in the script you shared:
//Call parent constructor
parent::__construct($orientation,$unit,$format);
So when you run new PDF() it will call the contructor of the PDF-class, which will call the constructor of FPDF.
When you call the constructor again as mentioned in your answer by using the $this->__construct($orientation,$unit,$format); line, this will result in the PDF-contructor to be called twice.
I seem to have some misconceptions on how autoloading works in PHP still, one I simply cannot explain.
I have a class called glue which has a spl_autoload_register within it's main function, here called run like so:
class glue{
public static function run(){
spl_autoload_register(array('glue','autoload'));
}
}
The autoload function works by loading via the PSR-0 standard and works from absolute paths. This is all tested as working etc. Note that glue is not namespaced.
The autoload function covers a namespace called glue. Within this namespace I have a error handler called \glue\ErrorHandler.
When I trigger an error the glue class will autoload \glue\ErrorHandler by PSR-0 notation from the root directory as defined by a stored ROOT constant. This has been tested as working as well in classes such as \glue\User and \glue\Session.
So now for the problem. I cause a Call-time pass-by-reference has been deprecated error within \glue\Validation and it doesn't seem to run my autoload function.
I can see how it is going into my autoload function for everything but when I call this error in that class it just seems to skip my autoloader and bail out saying it can't find my error handler class.
Normally I would say it is something with my programming but I have tried everything. I cannot explain how, for this one error. What compounds my confusion further is that if I cause a:
syntax error, unexpected T_ISSET in /media/server_ws/xxxxxxx/glue/Validation.php on line 47
Error it works. It seems to be for that one error it just will not autoload my error handler.
I thought this might be because my spl_autoload_register is not being binded to that namespace (since the error handler that works is actually called from within glue) and some how, maybe, it is randomly working. So from \glue\Validation I called a class I have never looked at: \glue\util\Crypt but that works and goes into the autoloader correctly.
When I call this error: Call-time pass-by-reference has been deprecated from within glue class it works perfectly.
Can anyone shed some light on this?
Edit
As requested here is a brievated version of Validation.php:
namespace glue;
use glue,
\glue\Exception,
\glue\Collection;
class Validation extends \glue\Component{
private function validateRule($rule){
// This is the line, notice the pass by reference down there?
$valid = $validator($field,$field_value,$params,&$this->model) && $valid;
}
}
The Call-time pass-by-reference has been deprecated error is thrown during script compilation, and auto-loading is disabled during compilation. It's disabled because the compiler cannot start compiling multiple scripts at the same time (i.e. it is not re-entrant), and auto-loading may load some script, which may require compiling it.
Source: https://github.com/php/php-src/blob/76ad52ccc501c02aeb068d2eb4f119ef6f0c2b6a/Zend/zend_execute_API.c#L1058
I've been creating a script using PHP and seem to have hit a brick wall at the moment with it. I'm trying to call a variable from another file which is within a class, so I went about it by including the file within the original and then instantiating the class to call the variable. But the entire thing is within a recursive function and I get Fatal error: Cannot redeclare class JVersion. I've pasted part of the code below:
...
function functionname($path)
{
...
define('_JEXEC', true);
require_once ($path ."libraries/cms/version/version.php");
$test_class = new JVersion();
$jma_ver = $test_class->getShortVersion();
...
functionname($path);
...
}
This is how the part of the code within the version.php looks like
defined('_JEXEC') or die;
final class JVersion
{
public $RELEASE = '2.5';
public $DEV_LEVEL = '1';
public function getShortVersion()
{
return $this->RELEASE.'.'.$this->DEV_LEVEL;
}
Is there a way I can overcome the "Fatal error: Cannot redeclare class JVersion" error ?
If I understand the problem correctly (i.e. you have many classes named JVersion that you need to use), then I'm not sure of any way around this problem without namespacing your JVersion classes in some way. Either give them distinct names or put them in different PHP namespaces.
This sounds more like an architectural problem, really; the code you're using doesn't seem to provide a way of getting its version in a disposable manner (without setting yourself up for conflicts like this). Ideally, you should just have a global JVersion class that can be insantiated with the appropriate version numbers; this way there'd be no class name conflicts.
Does anyone have a clue about this? PHP 5.2.13. Results not wholly consistent i.e. could get a good result with a page at one time, then get an error at another.
The error is fatal - class does not have method.
But the following are true:
The class is defined in only one place and has the relevant method in the code.
At the point where failure occurs: reflection shows that the method exists.
At the point where failure occurs: method_exists says the method does not exist.
Previous calls (they're all static - not my choice) earlier in the code worked.
May be it's related: http://bugs.php.net/bug.php?id=51425
But I think here we have some cache-related problem. Do you have some cache enabled? Like APC or any other accelerators?
Be sure that the file containing the method is included. If the method is in a class, make sure the class instance is created and the method is called through the class.
Maybe you are missing the class instance?
I have trying to solve the error : Fatal error: Cannot redeclare class
I have been looking everywhere and I can't find where the class was instantiated.
Is there anyway I can print debug info about the existing instance of that class.
Chances are you are importing the file that declares the class more than once. This can be symptomatic of includes/requires getting out of control so you may need to simply your structure.
One alternative approach is to use autoload to load classes to avoid this kind of problem. Another is to only use include_once or require_once. I generally prefer to use require with a simple structure.
Yes, stupid php doesn't tell you where the class was declared. Try the following (immediately before fatal error line)
$r = new ReflectionClass("YourClassName"); echo $r->getStartLine();
You can find out, where an object was instantiated by using var_dump(debug_backtrace()); and looking at the call stack.