Jump to content

Class instantiation not working; variable returned in method not getting value


cgm225

Recommended Posts

Below I have created a snippet of code to pose a problem I am having with the getLimit() method.  Basically, I want to instantiate the class as shown below, and expect it to output the number "100" but instead there is no output.  I know that the value 100 is making it to the setNumberDisplayed, setPageLimits, and setLimit methods, but then I end up with an empty $this->limit in the getLimit() method, so nothing is returned.  What am I doing wrong such that the getLimit() method is not returning "100"?

 

<?php

class Example {
    public function setNumberDisplayed($number) {
        $this->numberDisplayed = $number;
        }

    public function setPageLimit() {
        $this->setPageLimit = $this->numberDisplayed;
        $this->setLimit($this->setPageLimit);
    }

    public function setLimit($limit) {
        $this->limit = $limit;
    }
    
    public function getLimit() {
        return $this->limit;
    }
}

$example = new Example;
$example->setNumberDisplayed(100);
$example->setPageLimit();
echo $example->getLimit;

?>

echo $example->getLimit;

 

should be -

 

echo $example->getLimit();

 

When learning php, developing php code, or debugging php code, always turn on full php error reporting to get php to help you. The above problem causes a Notice error message.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.