Discussion:
Redefining base class functions?
(too old to reply)
Benjamin Smith
2008-06-13 21:48:42 UTC
Permalink
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.
kksou
2008-06-20 06:24:29 UTC
Permalink
Post by Benjamin Smith
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
--
View this message in context: http://www.nabble.com/Redefining-base-class-functions--tp17832602p18023768.html
Sent from the Php - GTK - General mailing list archive at Nabble.com.
Elizabeth M Smith
2008-06-20 12:35:03 UTC
Permalink
Post by kksou
Post by Benjamin Smith
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

Loading...