Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Supporting Technologies > Server-Side Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-25-2004, 02:09 PM   #1
boyzdynasty
Senior Member
 
boyzdynasty's Avatar
 
Join Date: Aug 2002
Location: Philly
Posts: 2,583
Unhappy PHP: Class extending a Class

Class1

Class2 extends Class1

Class3 extends Class2


In Class2 I have a constructor that does not take in any arguements but it sets up some value to some variables.

When create an object of Class3, I assumed that the constructor for Class2 would be called and set up values for the variables in Class2.

But it didn't.

$test = new Class3();

echo "some value: $test->var1"; // var1 is a variable from Class2

The result was empty (nothing was set).

How do I get the Constructor of Class2 to be executed when I create an object of Class3 ?


Thanks in advance.
__________________
I need a new signature!
boyzdynasty is offline   Reply With Quote
Old 04-25-2004, 02:54 PM   #2
boyzdynasty
Senior Member
 
boyzdynasty's Avatar
 
Join Date: Aug 2002
Location: Philly
Posts: 2,583
Default

This is a bit strange....

If I want Class2 constructure called, I cannot have a constructor in Class3.
__________________
I need a new signature!
boyzdynasty is offline   Reply With Quote
Old 04-25-2004, 11:13 PM   #3
splict
spend my time in blender
 
splict's Avatar
 
Join Date: Oct 2003
Location: tampa, fl
Posts: 1,138
Default

Well, in order to call the super's constructors or methods you should use super(); or super.myMethod(); However, if you don't explicitly call the super's constructor, I think actionscript should call it automatically. Could you post a bit of code, or a short example?
__________________

Certified Flash MX 2004 Developer
splict is offline   Reply With Quote
Old 04-26-2004, 12:13 AM   #4
boyzdynasty
Senior Member
 
boyzdynasty's Avatar
 
Join Date: Aug 2002
Location: Philly
Posts: 2,583
Default

i was thinking that too...cuz that is how i do it in JAVA

but I did a search for php and super...and didn't find anything.

So i figure i can't do that.
__________________
I need a new signature!
boyzdynasty is offline   Reply With Quote
Old 04-26-2004, 03:00 AM   #5
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

I think you have to call super () manually if you're using php 4, but not totally sure on that.
retrotron is offline   Reply With Quote
Old 04-26-2004, 03:17 AM   #6
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Yeah, look at this:
PHP Code:
<?php

class Class1 {

    function 
Class1 () {
        print (
'Class1 constructor invoked <br />');
    } 
// end constructor
    
    
function Class1_foo () {
        print (
'Class1_foo () invoked <br />');
    } 
// end Class1_foo ()

// end Class1 

class Class2 extends Class1 {

    function 
Class2 () {
        print (
'Class2 constructor invoked <br />');
    } 
// end constructor

// end Class2

$c = new Class2;

?>
If you run that, only the constructor for Class2 is invoked. So PHP doesn't automatically invoke superclass constructors. To do that, you have to manually call the superclass constructor with parent::superclassName (), like this:

PHP Code:
<?php

class Class1 {

    function 
Class1 () {
        print (
'Class1 constructor invoked <br />');
    } 
// end constructor
    
    
function Class1_foo () {
        print (
'Class1_foo () invoked <br />');
    } 
// end Class1_foo ()

// end Class1 

class Class2 extends Class1 {

    function 
Class2 () {
        
parent::Class1 ();
        print (
'Class2 constructor invoked <br />');
    } 
// end constructor

// end Class2

$c = new Class2;

?>

Last edited by retrotron; 04-26-2004 at 03:20 AM.
retrotron is offline   Reply With Quote
Old 04-26-2004, 04:39 AM   #7
splict
spend my time in blender
 
splict's Avatar
 
Join Date: Oct 2003
Location: tampa, fl
Posts: 1,138
Default

Yeah, I am an idiot. Of course php doesn't automatically call the super's constructor. If you read my post carefully, you can see I wrote actionscript even though it was obvious you were using php. I guess if I'm not gonna take the proper amount of time to sit and read a post before I answer it, I probably shoudln't answer, huh?

-splict
__________________

Certified Flash MX 2004 Developer
splict is offline   Reply With Quote
Old 04-26-2004, 09:31 AM   #8
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Heh heh, I noticed the 'actionscript', and I just laughed. Hee hee, good times, good times.
retrotron is offline   Reply With Quote
Old 04-26-2004, 09:34 AM   #9
splict
spend my time in blender
 
splict's Avatar
 
Join Date: Oct 2003
Location: tampa, fl
Posts: 1,138
Default

Well, as long as I provided you with a bit of entertainment, my public embarassment was worth every second.
__________________

Certified Flash MX 2004 Developer
splict is offline   Reply With Quote
Old 04-26-2004, 09:39 AM   #10
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

:d :d :d

<edit>

...um....those are supposed to be grins...



</edit>
retrotron is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:08 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.