Include and Require
Shared Helpers
An included helper can keep shared labels in one place.
reusable labels
The main file can combine local input with labels loaded from a helper.
Shared Helpers
shared_helpers.php
Replay: real traced execution (multi-file project)
<?php
$score = 75;
include __DIR__ . "/score_helper.inc";
if ($score >= 90) {
$label = $excellentLabel;
} elseif ($score >= 70) {
$label = $steadyLabel;
} else {
$label = $practiceLabel;
}
echo "score=" . $score . "\n";
echo "label=" . $label . "\n";
<?php
$score = 55;
include __DIR__ . "/score_helper.inc";
if ($score >= 90) {
$label = $excellentLabel;
} elseif ($score >= 70) {
$label = $steadyLabel;
} else {
$label = $practiceLabel;
}
echo "score=" . $score . "\n";
echo "label=" . $label . "\n";
<?php
$score = 95;
include __DIR__ . "/score_helper.inc";
if ($score >= 90) {
$label = $excellentLabel;
} elseif ($score >= 70) {
$label = $steadyLabel;
} else {
$label = $practiceLabel;
}
echo "score=" . $score . "\n";
echo "label=" . $label . "\n";
$score ← 75, $label ← NULL
1<?php2$score→ 75 = 75; //@score=55, 953include __DIR__ . "/score_helper.inc";4if ($score >= 90) {5 $label = $excellentLabel;6} elseif ($score >= 70) {7 $label→ NULL = $steadyLabelNULL;8} else {9 $label = $practiceLabel;10}1112echo "score=" . $score75 . "\n";13echo "label=" . $labelNULL . "\n";outputscore=75 label=
$score ← 55, $label ← NULL
1<?php2$score→ 55 = 55;3include __DIR__ . "/score_helper.inc";4if ($score >= 90) {5 $label = $excellentLabel;6} elseif ($score >= 70) {7 $label = $steadyLabel;8} else {9 $label→ NULL = $practiceLabelNULL;10}1112echo "score=" . $score55 . "\n";13echo "label=" . $labelNULL . "\n";outputscore=55 label=
$score ← 95
1<?php2$score→ 95 = 95;3include __DIR__ . "/score_helper.inc";4if ($score >= 90) {$label ← NULL
3include __DIR__ . "/score_helper.inc";4if ($score95 >= 90) {5 $label→ NULL = $excellentLabelNULL;6} elseif ($score >= 70) {echo "score=" . $score . " ";
12echo "score=" . $score95 . "\n";13echo "label=" . $labelNULL . "\n";outputscore=95 label=