Call to a member function on a non-object
It means that $objPage
is not an instance of an object. Can we see the code you used to initialize the variable?
As you expect a specific object type, you can also make use of PHPs type-hinting featureDocs to get the error when your logic is violated:
function page_properties(PageAtrributes $objPortal) {
...
$objPage->set_page_title($myrow['title']);
}
This function will only accept PageAtrributes
for the first parameter.
PHP Fatal error: Call to a member function on a non-object
Because in foreach loop you have taken news as variable which overides the object value of the news and makes it a variable..
You can try changing the variable name to some other names or change the object name.In the related line use
$obj = new Admin_NewsTable( $dbh );
and invoke class method using
$obj->getNewsPost($updateId);
call to a member function non-object
Do not chain calls to query()
and fetchAll()
like you are doing. That's bad practice. Never assume your query worked, always check to see if it did.
$db = option('db');
$query = $db->query('SELECT ...');
if($query === FALSE){
print_r($db->errorInfo());
die;
}
$members_all = $query->fetchAll();
(Since you are calling fetchAll()
, I assume you are using PDO (and not MySQLi))
Also, do not try to concatenate variables into your SQL query. (P.S. You're not even doing that, you are using single quotes, so $current_members["interest"]
is not being read as a variable) That's just asking for an SQL injection attack. What you want to do is use prepared statements.
$db = option('db');
$query = $db->prepare('SELECT * FROM members WHERE interest = ? ORDER BY lastname, firstname');
$exec = $query->execute(array($current_members['interest']));
if($exec === FALSE){
print_r($query->errorInfo());
die;
}
$members_all = $query->fetchAll();
Fatal error.. Call to a member function.. on a non-object
If you put $gcm = new GCM();
in the constructor of your Demand class, then the variable $gcm
will only be available in the constructor method.
If you want to be able to access the $gcm
variable throughout the Demand class you'll need to set it as a property of the class like so:
class Demand()
{
/**
* Declare the variable as a property of the class here
*/
public $gcm;
...
function __construct()
{
...
$this->gcm = new GCM();
...
}
function myFunction()
{
...
// You can access the GCM class now in any other method in Demand class like so:
$result = $this->gcm->send_notification($registatoin_ids, $message);
...
}
...
}
Call to a member function on a non-object
your function getHTMLByUrl
isnt returning what you think it is.
public function getHTMLByURL($url)
{
$site = new \DOMDocument();
return $site->loadHTML(file_get_contents($url));
}
its returning the boolean result of the loadHTML
call, not the object.
see here for the documentation.
what you need to do is:
public function getHTMLByURL($url)
{
$site = new \DOMDocument();
$site->loadHTML(file_get_contents($url));
return $site;
}
Call to a member function on a non-object
The problem isn't with the $name variable but rather with the $_engine variable. It's currently empty. You need to verify that the path specification to Smarty.class.php is correct.
You might try this to begin your debugging:
$this->_engine = new Smarty();
print_r($this->_engine);
If it turns out that $_engine is correct at that stage then verify that it is still correctly populated within the render() function.
Call to a member function get on a non-object
You are calling the method inside Search
statically (Search::getT();
) which will never fire the __construct()
method.
__construct()
gets fired upon instantiating the class ($search = new Search;
), not upon calling static methods (Class::method();
).
Simply instantiate your search object: $search = new Search;
Like so:
use App\Libraries\Search;
class GV
{
public function test() {
$search = new Search;
echo $search::getT() ? 'ok' : 'bad';
}
}
Call a member function on a non object
echo $current->getId(); // line 34
Fatal error: Call to a member function getIdentifiant() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/site/prototype/administration.php on line 34
WhatEVER you think happens, or whatEVER you see in your page, if the error says $current is not an object, it is not. It might not be null, but it could also be an array or anything that is not an object.
Also :
$current = new Activity();
$current = $listActivities->getCurrent();
Doesn't really makes sense to me.
Use
var_dump($listActivities->getCurrent());
To see what it exactly returns, and trust what errors say.
EDIT : And you may not even be looking at the right php script acually : The error says "getIdentifiant" while the code says "getId". Make sure you're looking at the right piece of code and refreshing the right page.
Call To A Member Function On A Non-Object - PHP
$movie->getByPerma($perma,$language);
is returning something that is not an object.
So I would
print_r($movie)
on line 2 and see what I'm getting.
The second wierd thing is in:
$movie['rating'] = $movie->getRating($movie['id']);
On the left side you are using $movie as an array and on the right side you are using it as an object and then again yo sent the parameter you use $movie['id'] as an array.
So:
If you are getting an array, the array cant have functions, the function should be outside a class and will be called like this:
getRating($movie['id'])
istead of
$movie->getRating($movie['id']).
If you are getting an object, and the object implements the function
getRating($movie_id)
then the way to access the properties of the object is:
$movie->rating and $movie->id
I'm asuming that the properties are declared public. This is not the correct way of doing it though... The properties should be private and you should implemente getters and setters for the objects properties like this:
private $rating;
public function get_rating()
{
return $this->rating;
}
In this case to get the rating, use
$movie->get_rating();
And to asign a value to the rating, implement
public function set_rating($r)
{
$this->rating=$r;
}
And asign value like this:
$movie->set_rating($some_rating);
Dunno if I helped or made everything more confusing :S but feel free to ask me questions :)
Related Topics
Query With Multiple Values in a Column
How to Change the Background Color of Dropdown List in Select Tag
How to Check If MySQL Results Returned Empty in PHP
How to Remove the Extra Square Bracket from Json Having Multiple Arrays
How to Get Data from Another Table Using Id from Another Table
How to Get Multiple Value from Post Variable Using Same Name
Calculate Size in Bytes of Json Payload Including It in the Json Payload in PHP
How to Resolve a Http 414 "Request Uri Too Long" Error
Extension Mysqli Is Missing, Phpmyadmin Doesn't Work
Laravel PHP Fatal Error: Require(): Failed Opening Required ... Bootstrap/Autoload.Php on Line 17
How to Generate Unique Random Value for Each User in Laravel and Add It to Database
How to Install and Use PHP on Macos Via Brew
Get Total Number of Members in Discord Using PHP
Laravel Ajax Response Return HTML Elements
Remove Comma on Last Item of Foreach
What Is the Regular Expression to Validate a Comma Delimited List But Ending With '&' and a Word
Group Array Data on One Column and Sum Data from Another Column