First Go at Classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan Little

    First Go at Classes

    So, here I am, I've been programming PHP for 6 years, and have never
    gotten into classes. Well, I finally decided to take the plunge, and
    here's my very first newbie question. How come this works (not in a
    class):

    $x = array("a" => array(), "b" => array());
    $z = &$x['b'];
    $x['b'][0] = "test";
    echo $z[0];

    And this doesn't:

    class Phorm {
    var $dSpace, $dEmail, $dValid, $dAckPg, $dDBLog, $dTXLog;

    function PhormProcessor( ) {
    $this->dSpace = array(
    "EMail" => array(),
    "Valid" => array(),
    "AckPg" => array(),
    "DBLog" => array(),
    "TXlog" => array()
    );

    $this->dEmail = &$this->dSpace['EMail'];
    $this->dValid = &$this->dSpace['Valid'];
    $this->dAckPg = &$this->dSpace['AckPg'];
    $this->dDBLog = &$this->dSpace['DBLog'];
    $this->dTXLog = &$this->dSpace['TXlog'];
    }
    }

    $Phorm = new Phorm;

    $Phorm->dSpace['Email'][0] = "test";

    echo $Phorm->dEmail[0];

    --
    Alan Little
    Phorm PHP Form Processor

  • Alan Little

    #2
    Re: First Go at Classes

    Carved in mystic runes upon the very living rock, the last words of Alan
    Little of comp.lang.php make plain:
    [color=blue]
    > And this doesn't:
    >
    > class Phorm {
    > var $dSpace, $dEmail, $dValid, $dAckPg, $dDBLog, $dTXLog;
    >
    > function PhormProcessor( ) {[/color]

    Sorry, it's supposed to be:

    class Phorm {
    var $dSpace, $dEmail, $dValid, $dAckPg, $dDBLog, $dTXLog;

    function Phorm() {

    I changed the name of the class without changing the name of the
    constructor. But it still isn't working.

    --
    Alan Little
    Phorm PHP Form Processor

    Comment

    • Alan Little

      #3
      Re: First Go at Classes

      Carved in mystic runes upon the very living rock, the last words of Alan
      Little of comp.lang.php make plain:
      [color=blue]
      > $this->dSpace = array(
      > "EMail" => array(),
      >
      > $Phorm = new Phorm;
      >
      > $Phorm->dSpace['Email'][0] = "test";
      >
      > echo $Phorm->dEmail[0];[/color]

      Gaaaahhh! Forget it! Wrong array key. Now I really do feel like a newbie.

      --
      Alan Little
      Phorm PHP Form Processor

      Comment

      Working...