SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Intermediate fun is not working

    Hi all,
    There is a problem.intermediate function calling in a class is not working.
    The print is only
    Hello ()
    The test.php is
    <?php
    require_once('class.Demo.php');
    $objDemo = new Demo();
    $objDemo->set('Steve');
    $objDemo->sa();
    ?>
    the class.Demo.php is
    <?php
    class Demo {
    private $_name;
    public function set($name) {
    //if ( !is_string($name) || strlen($name) == 0) {
    //throw New Exception("Invalid name value");
    //}
    $this->_name = $name;
    }
    public function getname() {
    return $this->_name;
    }

    public function sa() {
    print "Hello $this->getname() ";
    }


    }
    ?>
    why the intermediate function(getname() which is calling through sa() ) not printing the name steve
    Plz help me

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does it print? By the way this should be in the regular PHP forum.

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     public function sa() {
    print 
    "Hello $this->getname() ";

    This is the problem; I don't think you can directly output in this manner? You need to do this instead

    PHP Code:
     public function sa() {
    print 
    "Hello {$this->getname()} ";

    Now it works.

    By the way this should be in the regular PHP forum.
    But it is excusable since the lad is only starting out

  4. #4
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ujjwal, can you please enclose your code in the [ php ] and [ /php ] (without the spaces) tags so it is more readable. You are much more likely to get response when people can easily view your problem.

    You also might want to review the sticky threads:
    Where should I post my thread? and Read before you post ...
    for some guidelines as to where various topics belong in these forums.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  5. #5
    Resident Java Hater
    Join Date
    Jul 2004
    Location
    Gerodieville Central, UK
    Posts
    446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    PHP Code:
     public function sa() {
    print 
    "Hello $this->getname() ";

    This is the problem; I don't think you can directly output in this manner? You need to do this instead

    PHP Code:
     public function sa() {
    print 
    "Hello {$this->getname()} ";

    Now it works.



    But it is excusable since the lad is only starting out
    Well it depends on what you define to be "advanced"? At the end of the day, if someone classes something as advanced, it is normally advanced relative to their own experiences.

    Just some point less food for thought to add to a slightly off topic thread


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •