Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Changing a value of an extented class
Old 10-01-2009, 05:54 PM Changing a value of an extented class
Junior Talker

Posts: 2
Trades: 0
Hi,

I'm trying to run the code bellow but with no success. No error message but the value is not changed.

Code:
class A {
  public $item_limit;

   public function __construct(){
        $this->item_limit = null;
   }

  function test() {
    echo $this->item_limit;
  }

}

class B extends A {

   function My_test() {
        $tools = new A();
        if (isset($limit))
             $tools->item_limit = $limit;
   }
}  
Any help will be appreciated plz.

Best Regards
Denis Dulici

Last edited by denisdulici; 10-01-2009 at 06:43 PM..
denisdulici is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-02-2009, 09:31 AM Re: Changing a value of an extented class
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
It's a little hard, from you code, to see what you are trying to do...

Where does the $limit variable come from? In your code above it will hold no value, and the line

if (isset($limit))

will never be true.

Also, I'm not sure why you would create a new instance of class A inside the method My_test() in class B. Since B extends A, B is kind of a instance of class A already and you probably won't need to create a new instance of it.

My guess is, that you're trying to do something like this, which should work just fine.

PHP Code:
class {
   private 
$item_limit;

   public function 
__construct() {
      
$this->item_limitnull;
   }

   public function 
printLimit() {
      echo 
$this->item_limit;
   }
}

class 
extends {
   public function 
setLimit($limit) {
      
$this->item_limit $limit;
   }
}

$b = new B();
$b->setLimit(12);
$b->printLimit(); // should print 12 
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 10-02-2009, 01:18 PM Re: Changing a value of an extented class
Junior Talker

Posts: 2
Trades: 0
Hi lizciz,

Thank you very much for your reply. In fact I tried your code but with no succes then I created the new complex one written here.

Anyway, the issue was that the $item_limit value was nulled again in another place I fixed it, thank you.

Best Regards
denisdulici is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Changing a value of an extented class
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12252 seconds with 12 queries