Redefining base class functions?

View: New views
3 Messages — Rating Filter:   Alert me  

Redefining base class functions?

by Benjamin Smith :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there a way (PHP-GTK1) to redefine a base class method? Specifically, I
need to change set_usize() so that the values for X and Y can be
recalculated. The function I'm envisioning might look like:

define('SIZEMULTIPLIER', 1.5);
... snip ...
function set_usize($x, $y)
{
return
 parent::set_usize(round($x * SIZEMULTIPLIER), round($y * SIZEMULTIPLIER));
}

So far, I'm drawing blanks. Is this possible? Any ideas?

Thanks,

Ben
--
Only those who reach toward a goal are likely to achieve it.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


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


Re: Redefining base class functions?

by kksou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Benjamin Smith wrote:
Is there a way (PHP-GTK1) to redefine a base class method? Specifically, I
need to change set_usize() so that the values for X and Y can be
recalculated.
Hi Ben,

Don't think PHP-GTK1 or PHP-GTK2 allows you to redefine a base class or override an existing class method.

If you really need something like this now, maybe you could try this.

1) Do a global find and replace to change all set_usize($x, $y)  to my_set_usize($x, $y)
2) Then define my_set_usize($x, $y) as what you've wanted
function my_set_usize($x, $y) {
    set_usize(round($x * SIZEMULTIPLIER), round($y * SIZEMULTIPLIER));
}

I know the solution is primitive and not your ideal solution. But at least you have something working till they allow you to override existing methods.

Regards,
/kksou

Re: Re[PHP-GTK] defining base class functions?

by Elizabeth M Smith :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

kksou wrote:

>
> Benjamin Smith wrote:
>> Is there a way (PHP-GTK1) to redefine a base class method? Specifically, I
>> need to change set_usize() so that the values for X and Y can be
>> recalculated.
>>
>
> Hi Ben,
>
> Don't think PHP-GTK1 or PHP-GTK2 allows you to redefine a base class or
> override an existing class method.
>
That's not exactly true - in PHP-GTK2 you can extend a class and then
override a call in that class with your own version.

For example, you could extend GtkWindow and create a method

class MyWindow extends GtkWindow {
public method size($x, $y) {
// do something to $x
$x = $x + 5;
// do something to $y
if ($y > 10) {
$y = 5;
}
// then call the "real" method
return parent::move($x, $y);
}
}

To use this you'd create a window using
$window = new MyWindow();
not
$window = new GtkWindow();

I have no idea if this works in GTK1... I'd have to wonder why you're
using it at all.

Thanks,
Elizabeth

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