Page 1 of 1

Object as regular value?

Posted: Fri Aug 14, 2009 6:58 am
by Edin
Is it possible to create object that acts like regular values.

Here is sample of class definition:

Code: Select all

 
class IntValue
{
    private $_value;
    
    function setValue($val)
    {
        $this->_value = $val;
    }
    function getValue()
    {
        return $this->_value;
    }
}
 
Is it possible to create class like this one that could be used in expressions
like.

$intValue = new IntValue();
$intValue = 5; // calls setValue(5)

//calls getValue
$result = $intValue * 100;

echo $result // prints 500

Re: Object as regular value?

Posted: Fri Aug 14, 2009 10:09 am
by jackpf
I believe not. Why can't you just call the functions?

Re: Object as regular value?

Posted: Mon Aug 17, 2009 3:38 am
by Edin
I am working on template engine similar to asp.net one.

Here is sample of syntax:

Code: Select all

 
<PHP:Panel ID="myPanel" Title="My Panel">
 
</PHP:Panel>
 

To make this tag to work class PHP_Panel must be defined like this

Code: Select all

 
class PHP_Panel extends BaseControl
{
    public $Title
    function Render()
    {
        //Render panel here
    }
}
 
I was looking for solution to bind propoerty with variable like:

Code: Select all

 
<PHP:Panel ID="myPanel" Title="{title}">
</PHP:Panel>
 
Title = "{title}" is assings a variable to property, this is evaluted when requested
using current DataRow.


This is also completed but i have to change all Public declaration to Protected and
override __call, __set and __get. I tought that this solution would be slow but i don't see any performance loss.