Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2007-04-06, 03:08 PM
Junior Member
 
Join Date: Dec 2006
Posts: 10
xploita is on a distinguished road
Default gather classes together

hello,
using php4
i'm having a problem gathering all my classes together.i have three classes(ErrorHandler,i18n and templateEngine),placed in separate files.
should i create one class and inherit from it or what?
another thing,the following example is not working.any ideas why not?
Code:
<?php
class A
{
    var $name = "name";
    function getname()
    {
       return $this->name;
    }
}

class B 
{
    function bar()
    {
        $name = A::getname();
        echo $name;
    }
}
?>
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2007-04-07, 03:58 PM
Senior Member
 
Join Date: Jul 2006
Location: Prague, Czech Republic
Posts: 193
vladimir_cz is on a distinguished road
Send a message via ICQ to vladimir_cz Send a message via MSN to vladimir_cz Send a message via Yahoo to vladimir_cz Send a message via Skype™ to vladimir_cz
Default

Hi!

your example will not work.
Reason: you have class A with defined variable. but when you use "A::method()" you don't create class variable. you just call methods from class. So, in methods of class "A" variable $this not defined at this moment.
for right work you can use:
PHP Code:
$classA = new A();
$name $classA->getname();
echo 
$name
Take look on any book about Object-Oriented Programming, read section about anonymous copy of class.
__________________
Thank you. Vladimir, Czech Republic.
http://www.smartwebco.com/
I'm looking for job.
Reply With Quote
  #3 (permalink)  
Old 2007-04-07, 04:02 PM
Senior Member
 
Join Date: Jul 2006
Location: Prague, Czech Republic
Posts: 193
vladimir_cz is on a distinguished road
Send a message via ICQ to vladimir_cz Send a message via MSN to vladimir_cz Send a message via Yahoo to vladimir_cz Send a message via Skype™ to vladimir_cz
Default

Quote:
Originally Posted by xploita View Post
i'm having a problem gathering all my classes together.i have three classes(ErrorHandler,i18n and templateEngine),placed in separate files.
should i create one class and inherit from it or what?
just create class variables from your different class.
PHP Code:
include_once('templateEngine.php');
$template = new templateEngine(<params>); 
class inherit need only for extend your classes. for add new methods to your class variables.
__________________
Thank you. Vladimir, Czech Republic.
http://www.smartwebco.com/
I'm looking for job.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:11 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.