I was receiving the following fatal error, running Joomla 2.5, but only while trying to access the administrative view of a custom component I have created (which accessed the database):
Fatal Error: Cannot access empty property in \libraries\joomla\database\database\mysqli.php on line 498"
The context of line 498 is:
protected function fetchObject($cursor = null, $class = 'stdClass'
{
return mysqli_fetch_object($cursor ? $cursor : $this->cursor, $class);
}
Bizarrely, even after removing the $this->cursor statement like so:
protected function fetchObject($cursor = null, $class = 'stdClass'
{
return mysqli_fetch_object($cursor, $class);
}
I received the same error, despite the fact that that line no longer contains a member access operator.
How could I be receiving this error even though no properties are being accessed in that line?
Related
I Newly Create Joomla Component using Framework on Framework. Administrator Section Working Fine. In Site Section Display Following Error. How to Resolve this Error.
Catchable fatal error: Argument 1 passed to FOFTable::setInput() must
be an instance of FOFInput, instance of F0FInput given, called in
/var/www/testjoomla/libraries/f0f/table/table.php on line 434 and
defined in /var/www/testjoomla/libraries/fof/table/table.php on line
3236
in my Dispatcher code :
include_once JPATH_LIBRARIES.'/fof/include.php';
class GulfJobDispatcher extends FOFDispatcher
{
public function onBeforeDispatch() {
$result = parent::onBeforeDispatch();
if($result) {
// Load Akeeba Strapper
include_once JPATH_ROOT.'/media/akeeba_strapper/strapper.php';
AkeebaStrapper::bootstrap();
AkeebaStrapper::jQueryUI();
AkeebaStrapper::addCSSfile('media://com_gulfjob/css/frontend.css');
}
return $result;
}
}
change F0F to FOF in your Controller or Other Area
I want to test this method:
Class:
public function bind(\Elastica\ResultSet $result = null) {
if (!$result instanceof \Elastica\ResultSet) {
throw new \InvalidArgumentException('I need an instance of \Elastica\ResultSet');
}
$this->bindedData = $result->getResults();
$this->isBinded = true;
}
Test
public function testGetTransformedDataNotSuccesful() {
$this->object->bind(new \stdClass()); //This throws a Catchable fatal error
}
My question is:
How can i test this?
An alternative is not to Type Hint the method var.
Or shouldn't i test this.
Wouldn't it make sense that PHP throws an exception instead of throwing a fatal error ?
Throwing a fatal error is correct, as your method signature explicitly asks for a \Elastica\ResultSet but you provide an \stdClass.
Removing the typehint would also remove the fatal error - but that doesn't make much sense imho :)
edit
This test should pass
public function testGetTransformedDataNotSuccesful() {
$this->setExpectedException(get_class(new PHPUnit_Framework_Error("",0,"",1)));
$this->object->bind(new \stdClass()); //This throws a Catchable fatal error
}
Slightly confused with PHP because it does not declare object variable types.
This is simplified code which does not work. I get why I get an error but not sure how in PHP I can specify that $pb is a PushBot object and so it has methods which can be used.
class Bot
{
public $pb;
//Constructor
function __construct(){
require_once('../PushBots.class.php');
// Application ID
$appID = '';
// Application Secret
$appSecret = '';
// Push The notification with parameters
$this ->pb = new PushBots();
$this ->pb->App($appID, $appSecret);
}
//Method. The $this->pb->Push() does not work
public function sendMessage(){
$this->pb->Push();
}
}
//Client calling the class
$bot = new Bot();
$bot->sendMessage();
The error I get is :
Parse error: syntax error, unexpected '$' for when the line
$this->pb->Push();
is called.
I guess its because it does not know that $pb is a PushBot object at this stage ?
Can I not declare it something like :
Public Pushbot $pb;
Parse error: syntax error, unexpected '$' for when the line
This is a parse error, meaning your code has not even been run yet. Check your code for any sytnax errors (the code you posted does not contain the syntax error).
how in PHP I can specify that $pb is a PushBot object
Although unrelated to the syntax error, if you were using some sort of dependency inversion you could use type-hinting to require a certain object to be passed:
// will cause fatal error if anything other than an object of type Pushbot is passed
function __construct(Pushbot $pb)
I'd like to use stdClass to store options for some methods, instead of passing huge lists of variables (inspired by javascript-style coding)
However, I'd like to make sure I'm always getting an instance of stdClass as an argument. I know I can add a hint in the argument (gb::search below) but when I deliberately try to break it, I'm not sure how to handle the error.
Any tips?
class gb extends CI_Model {
protected $searchtypes = array('full','partial');
protected $endpoint = "https://local.endpoint";
function __construct() {
parent::__construct();
// sample search
$options = new stdClass();
$options->term = 'sample search';
$options->type = 'full';
$this->search($options);
}
function clean_term($term){
$term = trim($term);
return $term;
}
function search(stdClass $options){
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}
The error it throws is something like:
A PHP Error was encountered
Severity: 4096
Message: Argument 1 passed to gb::search() must be an instance of stdClass, null given, called in /application/models/gb.php on line 20 and defined
Filename: models/gb.php
Line Number: 29
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 31
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 32
Any ideas how to approach this from a CodeIgniter point of view?
if I remember - mistyped argument should raise E_RECOVERABLE_ERROR, so, it triggers error handler but execution continues. So, you have two options basically.
One is to throw exception in error handler when E_RECOVERABLE_ERROR is encountered. To halt execution.
Another - check type with instanceof stdClass and do what you suppose - raise exception or return something.
UPDATE In your case your framework (CI is for CodeIgniter?) sets error handler (somewhere using set_error_handler). So, after logging or printing error message execution continues. (If there was not handler you would get fatal error). Just test type of argument manually:
function search(stdClass $options){
// test type for sure, because of recoverable error
if (!($options instanceof stdClass)) {
return false; // or throw new InvalidArgumentException('Parameter should be instance of stdClass');
}
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}
I am getting the following error in the following code:
Class primeField implements field {
private $intmodulus = '';
public function generator(){
return ;
}
public function modulus(){
return $this->$intmodulus;
}
public function __construct($modulus , $base=0) {
if (is_resource($modulus) && get_resource_type($modulus) == "GMP integer"){
$this->$intmodulus = $modulus;
} else{
$this->$intmodulus = gmp_init($modulus , $base); \\line 70
}
}
}
$a = new primeField(11);
$a->modulus();
Notice: Undefined variable: intmodulus in /Users/admin/PHP ECC/finitefield.php on line 70
Fatal error: Cannot access empty property in /Users/admin/PHP ECC/finitefield.php on line 70
Why
The syntax is
$this->intmodulus
not $this->$intmodulus.
You get an error saying "cannot access empty property" because $intmodulus is undefined and hence accessing it gives NULL. The NULL gets converted into an empty string when you attempt to use it as a property name.
If the value of $intmodulus was the name of a valid property (e.g. if $intmodulus == "intmodulus"), you would be accessing the property with that name.
$this->$intmodulus should be $this->intmodulus
See the PHP documentation for Variable variables for info on what is happening.