On Fri, 2003-06-27 at 03:09, Dave Alger wrote:
> Hiya,
> 
> It would be useful for me to be able to use a class within another class and
> I don't know if that's permissable in PHP.

Hi there!

It is indeed possible. However, that's not the problem here. The problem
is that class attribute initializers can only be constant values (i.e. 
no variables or non-constant expressions). This is explained in the 
manual's section on Classes and Objects:

  http://www.php.net/manual/en/language.oop.php

Specifically, check out the note right after the Caution box.

> Here's an example of what I'm trying to do. Is it just simply not permitted
> or am I going about it the wrong way?

[snip]

This is a minor rewrite which shows one way to do what you want:

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

class CSSFont
{
    var $family ='Arial';
    var $size ='12pt';
    var $style = 'none';
    function Output()
    {
        $out = "\n";
        $out .= "font-family:".$this->family.";\n";
        $out .= "font-size:".$this->size.";\n";
        $out .= "font-style:".$this->style.";\n";

        return $out;
    }
}

class CSSBorder
{
    var $font1;
    var $font2;
    var $out = '';

    function Output()
    {
        $this->out = $this->font1->Output();
        $this->out .= " other stuff goes here ";
        $this->out .= $this->font2->Output();
    }

    function Display()
    {
        echo $this->out;
    }

    function CSSBorder() 
    {
        $this->font1 = new CSSFont;
        $this->font2 = new CSSFont;
    }
}

$border = new CSSBorder();
$border->Output();
$border->Display();

?>


> Thanks in advance for any help,
> 
> Dave


Hope this helps clarify things,

Torben

-- 
 Torben Wilson <[EMAIL PROTECTED]>                        +1.604.709.0506
 http://www.thebuttlesschaps.com          http://www.inflatableeye.com
 http://www.hybrid17.com                  http://www.themainonmain.com
 -----==== Boycott Starbucks!  http://www.haidabuckscafe.com ====-----




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to