Using a function within a class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bloke Smith

    #1

    Using a function within a class

    I have written a class (and it works!).
    Now I want to tidy the code a bit by separating some subroutines and I
    get a "Fatal error: Call to undefined function:"

    e.g.
    class Fred{
    function Fred(){
    //constructor

    do_this();
    }

    function do_this(){ blah blah }
    }

    Please can someone tell what I'm doing wrong? If I use
    function_exists (do_this) it returns false.
    I've tried putting the function as the first block in the class.
    I've tried calling it as a method e.g. $this->do_this();

    PHP 4.3.9 on IIS (localhost)

    Thanks in advance

    Pete
  • Jerry Stuckle

    #2
    Re: Using a function within a class

    Bloke Smith wrote:[color=blue]
    > I have written a class (and it works!).
    > Now I want to tidy the code a bit by separating some subroutines and I
    > get a "Fatal error: Call to undefined function:"
    >
    > e.g.
    > class Fred{
    > function Fred(){
    > //constructor
    >
    > do_this();
    > }
    >
    > function do_this(){ blah blah }
    > }
    >
    > Please can someone tell what I'm doing wrong? If I use
    > function_exists (do_this) it returns false.
    > I've tried putting the function as the first block in the class.
    > I've tried calling it as a method e.g. $this->do_this();
    >
    > PHP 4.3.9 on IIS (localhost)
    >
    > Thanks in advance
    >
    > Pete[/color]

    $this->do_this();

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Bloke Smith

      #3
      Re: Using a function within a class

      On Wed, 19 Oct 2005 18:23:36 -0500, Jerry Stuckle
      <jstucklex@attg lobal.net> wrote:
      [color=blue]
      >Bloke Smith wrote:[color=green]
      >> I have written a class (and it works!).
      >> Now I want to tidy the code a bit by separating some subroutines and I
      >> get a "Fatal error: Call to undefined function:"
      >>
      >> e.g.
      >> class Fred{
      >> function Fred(){
      >> //constructor
      >>
      >> do_this();
      >> }
      >>
      >> function do_this(){ blah blah }
      >> }
      >>
      >> Please can someone tell what I'm doing wrong? If I use
      >> function_exists (do_this) it returns false.
      >> I've tried putting the function as the first block in the class.
      >> I've tried calling it as a method e.g. $this->do_this();
      >>
      >> PHP 4.3.9 on IIS (localhost)
      >>
      >> Thanks in advance
      >>
      >> Pete[/color]
      >
      > $this->do_this();[/color]

      Dang! I coulda sworn I tried that yesterday and it didn't work. I must
      have had two errors.
      Thanks a lot.

      Comment

      Working...