Reputation: 93
I am new to php oop so please bear with me...
I have a method in a class called regions that is not returning a result and when I use method_exists
it say it does not exist. I can not see what I am doing wrong.
This is the class:
<?php
class SeniorMentor {
public $regions;
public function __toString() {
$output = '';
$output .= $this->uid . "<br>";
$output .= $this->fName . "<br>";
$output .= $this->lName . "<br>";
$output .= $this->email . "<br>";
return $output;
}
public function regions() {
$uid = 120;
include 'classes/con.php';
$stmt = $conn->prepare('SELECT region, region_id FROM regions WHERE uid = :uid');
$stmt->execute(array('uid' => $this->uid));
while($row2 = $stmt->fetchAll(PDO::FETCH_KEY_PAIR)) {
$regions = $row2;
return $regions;
}
}
}
This is the script calling it:
<?php
include 'classes/con.php';
include 'classes/SeniorMentor.php';
$uid = 120;
$seniorMentor = new SeniorMentor;
echo $seniorMentor->regions($uid);
var_dump(method_exists($seniormentor,'regions'));
$sq = $conn->query("SELECT * FROM primary_profile", PDO::FETCH_INTO, $seniorMentor);
while($row = $sq->fetch()) {
echo "$row <br/>";
}
?>
Thanks for taking a look
Upvotes: 1
Views: 1603
Reputation: 1005
In PHP Variables are Case-Sensitive. This means the $seniorMentor
and $seniormentor
are two completely different variables.
var_dump(method_exists($seniormentor,'regions'));
Should be:
var_dump(method_exists($seniorMentor,'regions'));
In most cases, I would recommend sticking with a standard naming convention to avoid this issue. The two most common are Camel Case and Delimiter Case.
Eg: Camel case $seniorMentor
Eg: Delimiter Case $senior_mentor
Upvotes: 5