niet extend maar ... ?

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Marc Cools

Marc Cools

09/11/2008 14:27:00
Quote Anchor link
Ik wil drie classes maken:

class Flag {
private $_flag;
private $_color
function foo(){
echo "Great foo function.";
}
...
}

class DateSpan{
private $_start;
private $_stop;
function bar(){
echo 'doe na ' . $_start . ' en voor ' . $_stop;
}
}

Nu wil ik een derde class maken van die twee andere classes.
En ik weet niet goed hoe ik dan moet doen.

class FlagDated extends Flag{
private $_datums;
function __construct(){
$this->_datums = new DateSpan;
}
}

Is dit een beetje juist?
Hoe roep ik de 'bar' functie aan?

Kortom hoe voeg je twee classes samen in één class.

Thanks.
 
PHP hulp

PHP hulp

26/04/2024 19:04:53
 
Joren de Wit

Joren de Wit

09/11/2008 14:33:00
Quote Anchor link
Dat klopt opzich wel wat je hebt, aanroepen van de bar() method binnen je FlagDated klasse kun je gewoon zo doen:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
$this
->_datums->bar();
?>
Gewijzigd op 01/01/1970 01:00:00 door Joren de Wit
 
Marc Cools

Marc Cools

09/11/2008 14:55:00
Quote Anchor link
Ik bedoel van buiten de FlagDated class.
 
Marc Cools

Marc Cools

09/11/2008 14:58:00
Quote Anchor link
Dus de laatste class alsof het één class is en niet samengesteld uit de twee andere.
 
--

--

09/11/2008 15:04:00
Quote Anchor link
Niet bumpen. :-)
Zie de FAQ.
 
Lode

Lode

09/11/2008 15:06:00
Quote Anchor link
Ligt een beetje aan de rest natuurlijk...
Je kan ook de objecten buiten de class aanmaken natuurlijk

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
class one{
    public function __construct($param){}
}

class two{
    public function __construct(array $params){}
}

class three{

    protected $_one = null;
    protected $_two = null;

    public function __construct(one $one, two $two){
        $this->_one = $one;
        $this->_two = $two;
    }
}



$first = new one('blaat');
$second = new two(array('value1', 'value2'));

$primairy = new three($first, $second);
?>


Ligt er maar net aan wat je allemaal van plan bent.
 
Marc Cools

Marc Cools

09/11/2008 15:45:00
Quote Anchor link
Stel:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
class Tong{
    function
steekTongUit(){}
}

class Arm{
    function
beweegArm(){}
}

class Hoofd{
    protected $_tong = null;
    function
__construct(){
        $this->_tong = new Tong
    }
    function
beweegHoofd(){}
}

class Lichaam{
    protected $_hoofd = null;
    protected $_linkseArm = null;
    protected $_rechtseArm = null;
    function
__construct(){
        $this->_hoofd = new Hoofd;
        $this->_linkseArm = new Arm;
        $this->_rechtseArm = new Arm;
    }
}

?>


Ik kan dan:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<?php
$greatBody
= new Lichaam;
// Dit kan:
$greatBody->_hoofd->beweegHoofd();
$greatBody->_linkseArm->beweegArm();
// maar ik zou liever hebben  alsof het dus maar één class was en niet opgebouwd uit diverse classes.
$greatBody->beweegHoofd()
$greatBody->steekTongUit()
// Stel je voor:
$greatBody->_linkseArm->_hand->_middelvinger->steekOp();
// dat moet toch korter kunnen met behoud van de diverse classes
?>


Begrijp je waar ik naartoe wil?

Eigenlijk een soort import functie.
Gewijzigd op 01/01/1970 01:00:00 door Marc Cools
 
Lode

Lode

09/11/2008 16:24:00
Quote Anchor link
protected vars zijn 'protected' die kan je dus niet zomaar aanroepen buiten de class scope. Dan moet je ze public maken.
public vars zijn oncontroleerbaar omdat ze door jan en alleman geset / unset kunnen worden. Dus niet er handig.

Beter zijn getter en setter functies:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
class Lode_Arm{
    public function getLength(){
         return '100 cm';
    }
}

class Lode{

    protected $_arm = null;
    protected $_head = null;

    public function __construct(){
         $this->_arm = new Lode_Arm();
         $this->_head = new Lode_Head();
    }

    public function getArm(){
         return $this->_arm;
    }

    public function getHead(){
         return $this->_head;
    }
}



$lode = new Lode;
$lode->getArm()->getLength(); // 100 cm.
?>


Maar dit voegt niet echt veel toe denk ik. Meer objecten alleen.

Misschien een factory pattern anders?

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
class Lode{
    
    static public function factory($element){
         switch($element){
               case
'arm' :
                   return new Lode_Arm();
               case
'head' :
                   return new Lode_Head();
               default:

                   return null;
         }
    }
}


Lode::factory('arm')->getLength(); // 100 cm.
?>


Allemaal leuk en aardig een lichaams voorbeeld, maar de daad werkelijke toepassing is nog steeds een raadsel.

Misschien moet je gewoon een goed OOP boek lezen ofzo ?
Gewijzigd op 01/01/1970 01:00:00 door Lode
 
Marc Cools

Marc Cools

09/11/2008 19:16:00
Quote Anchor link
@Lode

Dus, je kan altijd een class extenden en zo er functies aan toevoegen en eventueel wijzigen. Maar twee classen 'extenden' in één nieuwe class kan niet. Blijkbaar ook niet met slim programmeerwerk.

Ik ben momenteel het boek <b>Head First Object-Oriented Analysis & Design</b> aan het lezen. Lijkt mij een goed boek.

Ik wil voor een database toepassing een 'flag' toevoegen.
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?php
class AttentFlag{
    protected $_flag, $_color, $_after, $_before;
}

?>

Lees ik toch wel in dat boek dat ik moet vermijden om code ergens tweemaal neer te zetten. Dat geeft alleen maar problemen als je de code wilt aanpassen. En ik voorzie dat ik apart de flag/color wil gebruiken en apart de after/before datums. Dus dacht Marc dat hij twee objecten hiervoor kon maken en die eventjes samensmelt tot een derde class alsof het een 'basis'-class is. Niet dus.

Ik zal het dus maar als volgt doen:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?php
class DateSpan{}
class Flag extends DateSpan{}
?>


Thanks iedereen.
Weeral veel geleerd.
Gewijzigd op 01/01/1970 01:00:00 door Marc Cools
 
Hipska BE

Hipska BE

09/11/2008 19:43:00
Quote Anchor link
Blijkbaar niet, want in OOP vertaal je de extends door 'is een soort van'.
In jou geval zou dat betekenen dat Flag een soort van DateSpan is...

Klopt niet echt he

even het typische voorbeeld met auto's:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php

// hoofdclasse
class auto { ... }

// volledig correct, SUV heeft een aantal andere instellingen en methoden
class suv extends auto { ... }

// dit klopt toch niet
// ik wil een stuur in de auto:

class stuur extends auto { ... }

// dan doe je het zo:
class auto {
    $stuur = new stuur();
}


// in jouw geval:
// een flag kan een DateSpan hebben, maar is er geen soort van.

class Flag {
    $datespan = new DateSpan();
}


?>
 
Marc Cools

Marc Cools

09/11/2008 22:32:00
Quote Anchor link
EDIT: aanpassingen na opmerkingen van Lode.

Hierna de DateTimeSpan class die ik gemaakt hebt.

@hipska
Tja dat klopt dus wat je schrijft.
Behalve als je de Flag als een datespan ziet met nog een bool en een color. De datespan is ook een soort flag die aangeeft wanneer je uw aandacht er op moet vestigen. Denk aan Outlook waarbij je ook een flag kan instellen welliswaar enkel met een duedate maar wel met een 'type'.
Als je de datespan bijvoorbeeld gebruikt om een afspraak vast te leggen dat is het niets meer van een flag.
Ik denk dat het arbitrair is. Wat denk jij?

In ieder gaval de DateTimeSpan class.
Waarschijnlijk vol met fouten . Laat je dus maar eens goed gaan. :)
Ik ben hier om te leren. Teach me!
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/**
* file    : DateTimeSpan.class.php
* version : $id$
* status  : alfa 0.02, not tested
* author  : Marc Cools
*
* This class handles a DateTime span.
*/

class DateTimeSpan {

# variables / constructor / destructor
    
    private $_startDate = null; # DateTime, holds the lower date
    private $_stopDate = null; # DateTime, holds the higher date

    /**
    * constructor
    *
    * @param DateTime $startDate, the lower date
    * @param DateTime $stopDate, the higher date
    */

    public function __construct($startDate = null, $stopDate = null){
        $this->_startDate = new DateTime($startDate);
        $this->_stopDate = new DateTime($stopDate);
    }


# methods

    /**
    * method : handling startDate.
    *
    * With no or null parameters it returns the value of the startDate.
    * With parameters it sets the startDate and also changes the stopDate when
    * requested.
    *
    * @param DateTime $newDate, the new date voor the startDate.
    * @param boolean $updateStopDate, also update the stopDate when true.
    *
    * @return DateTime The old or new startDate value.
    */

    public function startDate($newDate = null, $updateStopDate = true){
        if( !empty($newDate) ){
            if( strtolower($newDate == "null") ){
                $this->_startDate = null;
                if( $updateStopDate ){
                    $this->_stopDate = null;
                }
            }
else if( empty($this->_startDate) ){
                $this->_startDate = $newDate;
                if( $updateStopDate ){
                    $this->_stopDate = $newDate;
                }
else if( $this->_startDate < $this->_stopDate ){
                    $this->_stopDate = $this->_startDate;
                }
            }
else {
                $difference = $this->_stopDate - $this->_startDate;
                $this->_startDate = $newDate;                
                if( $updateStopDate ){
                    $this->_stopDate = $newDate->modify("+".$difference. " second");
                }
            }
        }

        return $this->_startDate;        
    }


    /**
    * method : handling stopDate.
    *
    * With no or null parameters it returns the value of the stopDate.
    * With parameters it sets the stopDate and also changes the startDate when
    * requested.
    *
    * @param DateTime $newDate, the new date voor the stopDate.
    * @param boolean $updateStartDate, also update the startDate when true.
    *
    * @return DateTime The old or new stopDate value.
    */
    
    public function stopDate($newDate = null, $updateStartDate = false){
        if( !empty($newDate) ){
            if( strtolower($newDate == "null") ){
                $this->_stopDate = null;
                if( $updateStartDate ){
                    $this->_startDate = null;
                }
            }
else if( empty($this->_stopDate) ){
                $this->_stopDate = $newDate;
                if( $updateStartDate ){
                    $this->_startDate = $newDate;
                }
else if( $this->_startDate < $this->_stopDate ){
                    $this->_startDate = $this->_stopDate;
                }
            }
else {
                $difference = $this->_stopDate - $this->_startDate;
                $this->_stopDate = $newDate;                
                if( $updateStartDate ){
                    $this->_startDate = $newDate->modify("-".$difference." second");
                }
            }
        }

        return $this->_stopDate;
    }

    
    /**
    * method : add a number of days to the DateTimeSpan.
    *
    * @param integer $days, the numbre of days to add to the stopDate.
    * @param boolean $posponeStartDate, also add days to the start date when true.
    * @param boolean $skipWeekends, skip the weekenddays when true.
    *
    * @return boolean True.
    */

    public function pospone($days = 1, $posponeStartDate = true, $skipWeekends = false){
        if( $skipWeekends ) {
            $days = floor($days / 5) * 2 + $days; # add 2 days for every week.
        }
        $this->_stopDate->modify("+".$days." day");
        if( $posponeStartDate ){
            $this->_startDate->modify("+".$days." day");
        }

        if( $skipWeekends ){
            $this->skipWeekendDay($this->_stopDate);
            $this->skipWeekendDay($this->_startDate);
        }

        return true;
    }

    
    /**
    * method : check if we are past the stopDate
    *
    * @return boolean
    */

    public function pastDue(){
        return ( !empty($this->_stopDate) && !($this->_stopDate >= date()) );
    }

    
    /**
    * method : check if we are before the startDate
    *
    * @return boolean
    */

    public function beforeStart(){
        return ( !empty($this->_startDate) || $this->_startDate <= date() );  
    }
    
    
    /**
    * method : check if we are in the datespan.
    *
    * @return boolean
    */

    public function betweenDates(){
        return ( !$this->beforeStart() && !$this->pastDue() )
    }

          
    /**
    * method : check if we are in the last 24 hours before due time.
    *
    * @param integer $lastDays, number of days to be considerd as last ones.
    *
    * @return boolean
    */

    public function due($lastDays = 1){
        $dueDate = $this->_stopDate;
        $dueDate->modify("-".$lastDays." day");
        return ( !pastDue() && $dueDate >= date() )
    }

      
    /**
    * method : check if there is none of the dates are set.
    *
    * @return boolean
    */

    public function noDates(){
        return( empty($this->_startDate) && empty($this->_stopDate) );
    }



# helper functions
    
    /**
    * Helper function for adding a day when it is a weekendday.
    *
    * @param DateTime The date to be checked.
    * @return DateTime The same date or the next date when it is a weekendday.
    */

    private function skipWeekendDay($date){
        if( date("N",$date) > 5 ){
            return skipWeekendDay($date->modify("+1 day"));
        }

        return $date;
    }

}

?>

Trots op mijn allereerste echte class. Als je hem wilt afschieten, schiet vriendelijk. :)
Gewijzigd op 01/01/1970 01:00:00 door Marc Cools
 
Lode

Lode

09/11/2008 23:00:00
Quote Anchor link
vars buiten quotes

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
"-$lastDays day"
?>


wordt:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
'-'.$lastDays.'day'
?>


nog netter is gewoon ook gelijk een negatief getal invoeren.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
return ( !beforeStart() && !pastDue() )
?>


Gaat nooit werken... moet zijn.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
return (!$this->beforeStart() && !$this->pastDue());
?>



Ik heb geen zin om je hele class te gaan herschrijven, maar hij is erg omslachtig volgens mij en relatief niet echt flexibel.
Gewijzigd op 01/01/1970 01:00:00 door Lode
 
Marc Cools

Marc Cools

10/11/2008 10:02:00
Quote Anchor link
Lode schreef op 09.11.2008 23:00:
Ik heb geen zin om je hele class te gaan herschrijven, maar hij is erg omslachtig volgens mij en relatief niet echt flexibel.

Ik denk dat je bedoeld dat ik slechts één methode heb om zowel get als set van een variabele te doen.
Ik zou dat kunnen oplossen door een getStopDate(), setStopDate() en dan in stopDate() die twee functies aan te roepen.
Ook stopDate en startDate is bijna hetzelfde. Zou met een helper functie simpelder kunnen gemaakt worden.
Gewijzigd op 01/01/1970 01:00:00 door Marc Cools
 
Marc Cools

Marc Cools

10/11/2008 16:36:00
Quote Anchor link
Versie 3 van mijn DateTimeSpan class:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
/**
* file    : DateTimeSpan.class.php
* version : $id$
* status  : alfa 0.03, not tested
* author  : Marc Cools
*/

/**
* This class handles a DateTime span.
*/

class DateTimeSpan {
# variables / constructor / destructor
{
    
    private $_startDate = null; # DateTime, holds the lower date
    private $_stopDate = null; # DateTime, holds the higher date

    /**
    * constructor
    *
    * @param DateTime $startDate, the lower date
    * @param DateTime $stopDate, the higher date
    */

    public function __construct($startDate = null, $stopDate = null){
        $this->_startDate = new DateTime($startDate);
        $this->_stopDate = new DateTime($stopDate);
        if($this->_startDate > $this->_stopDate){
            throw new exception("You can't stop before you begin.");
        }
    }

}

# methods
{

    /**
    * method : get the startDate.
    *
    * @return DateTime The value of startDate.
    */

    public function startDate(){
        return $this->_startDate;
    }


    /**
    * method : get the stopDate.
    *
    * @return DateTime The value of stopDate.
    */

    public function stopDate(){
        return $this->_stopDate;
    }

 
    /**
    * method : set startDate.
    *
    * It sets the startDate and also changes the stopDate when requested.
    *
    * @param DateTime $newDate, the new date voor the startDate.
    * @param boolean $updateStopDate, also update the stopDate when true.
    */

    public function setStartDate($newDate = null, $updateStopDate = false){
        $this->setDate($newDate, $this->_startDate, $this->_stopDate,
                $updateStopDate);
    }

    
    /**
    * method : set stopDate.
    *
    * It sets the stopDate and also changes the startDate when requested.
    *
    * @param DateTime $newDate, the new date voor the stopDate.
    * @param boolean $updateStartDate, also update the startDate when true.
    */

    public function setStopDate($newDate = null, $updateStartDate = false){
        $this->setDate($newDate, $this->_stopDate, $this->_startDate,
                $updateStartDate);
    }

  
    /**
    * method : add a number of days to the DateTimeSpan.
    *
    * @param integer $days, the numbre of days to add to the stopDate.
    * @param boolean $posponeStartDate, add days to the startDate when true.
    * @param boolean $skipNonWorkingdays, skip those days when true.
    */

    public function pospone($days = 1, $posponeStartDate = true,
            $skipNonWorkingdays = false){
        //NOTE: It counts a known holiday as a workingday. Needs a rewrite.
        if( $skipNonWorkingdays ) {
            $days = floor($days / 5) * 2 + $days; # add 2 days for every week.
        }
        $this->_stopDate->modify("+" . $days . " day");
        if( $posponeStartDate ){
            $this->_startDate->modify("+" . $days . " day");
        }

        if( $skipNonWorkingdays ){
            $this->skipNonWorkingday($this->_stopDate);
            $this->skipNonWorkingday($this->_startDate);
        }
    }

    
    /**
    * method : check if we are past the stopDate
    *
    * @return boolean
    */

    public function pastDue(){
        return ( !empty($this->_stopDate) && !($this->_stopDate >= date()) );
    }

    
    /**
    * method : check if we are before the startDate
    *
    * @return boolean
    */

    public function beforeStart(){
        return ( !empty($this->_startDate) || $this->_startDate <= date() );  
    }
    
    
    /**
    * method : check if we are in the datespan.
    *
    * @return boolean
    */

    public function betweenDates(){
        return ( !$this->beforeStart() && !$this->pastDue() )
    }

          
    /**
    * method : check if we are in the last 24 hours before due time.
    *
    * @param integer $lastDays, number of days to be considerd as last ones.
    *
    * @return boolean
    */

    public function due($lastDays = 1){
        $dueDate = $this->_stopDate;
        $dueDate->modify("-" . $lastDays . " day");
        return ( !$this->pastDue() && $dueDate >= date() )
    }


    /**
    * method : check if there is none of the dates are set.
    *
    * @return boolean
    */

    public function noDates(){
        return( empty($this->_startDate) && empty($this->_stopDate) );
    }

}
    
# alias methods
{  
  
    /**
    * alias for method setStopDate
    */

    public function setDueDate($newDate = null, $updateStartDate = false){
        $this->setStopDate($newDate, $updateStartDate);
    }


    /**
    * alias for method stopDate.
    */

    public function dueDate(){
        return $this->stopDate();
    }

}
    
# helper functions
{    
    
    /**
    * helper function for setting a date
    *    
    * @param DateTime $newDate, the new date voor the mainDate.
    * @param object-reference &$mainDate, the mainDate to be updated.
    * @param object-reference &$otherDate, the otherDate to be updated when asked.
    * @param boolean $updateOtherDate, also update the otherDate when true.
    */

    private function setDate($newDate, &$mainDate, &$otherDate, $updateOtherDate){  
        if( empty($mainDate) ){
            $mainDate = $newDate;
            if( $updateOtherDate ){
                $otherDate = $newDate;
            }
        }
else {
            $difference = $otherDate - $mainDate;
            $mainDate = $newDate;              
            if( $updateOtherDate ){
                $otherDate = $newDate->modify("+" . $difference . " second");
            }
        }

        
        if( $this->_startDate < $this->_stopDate ){
            $otherDate = $mainDate;
        }
    }


    /**
    * Helper function for adding a day when it is a weekendday.
    *
    * @param DateTime The date to be checked.
    * @return DateTime The same date or the next date when it is a weekendday.
    */

    private function skipNonWorkingday($date){
        // If it is a weekendday test voor the next day.
        if( date("N",$date) > 5 ){
            return skipNonWorkingday($date->modify("+1 day"));
        }

        // Extend this.
        // if christmas test voor the next day
        // and so one

        return $date;
    }

}

}

?>

En de uitbreiding:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* file    : Flag.class.php
* version : $id$
* status  : alfa 0.01, not tested
* author  : Marc Cools
*/


require_once("DateTimeSpan.class.php");

/**
* This class handles a flag with color and a DateTimeSpan.
*/

class Flag extends DateTimeSpan {
# variables / constructor / destructor
{

    private $_flag = null;
    private $_color = null;
 
    public function __construct($flag = false, $color = null,
            $startDate = null, $stopDate = null){
        parent::__construct($startDate, $stopDate);
        $this->_flag = $flag;
        $this->_color = $color;
     }
 }

 
# methods about $_flag
{
    
    public function flag(){
        return $this->_flag;
    }


    public function setFlag($value = null){
        if (is_bool($value)){
            $this->_flag = $value;
        }
    }

    
    public function on(){
        self::setFlag(true);
    }


    public function off(){
        self::setFlag(false);
    }


    public function toggle(){
        self::setFlag(!$this->_flag);
    }

}

 
# methods about $_color
{

    public function color(){
        return $this->_color;
    }

    
    public function setColor($value = null){
        $this->_color = $value;
    }

    
    public function red(){
        self::setColor('#FF0000');
    }

    
    public function green(){
        self::setColor('#00FF00');
    }

    
    public function blue(){
        self::setColor('#0000FF');
    }

}
 
}

?>


Graag uw commentaar zodat ik kan leren.
Gewijzigd op 01/01/1970 01:00:00 door Marc Cools
 
Rens nvt

Rens nvt

10/11/2008 16:38:00
Quote Anchor link
Geeft dit:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
<?php
    public function __construct($startDate = null, $stopDate = null){
        $this->_startDate = new DateTime($startDate);
        $this->_stopDate = new DateTime($stopDate);
        if($this->_startDate > $this->_stopDate){
            throw new exception("You can't stop before you begin.");
        }
    }

?>


geen uncaught exception als die check true is??
Gewijzigd op 01/01/1970 01:00:00 door Rens nvt
 
Marc Cools

Marc Cools

10/11/2008 17:04:00
Quote Anchor link
Ik heb geen flauw idee of was je vraag retorisch?
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.