PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

PHP · Theory

Static Variables

← All stacks

Theory

68/352

Static Variables

Static Variables is simple if you keep it on paper. Meera uses it for $marks = 72 in a result script.

Keep Static Variables small. Meera should finish $marks = 72 in a few lines, not a 40-line dump.

Without Static Variables, a result script gets messy and $marks = 72 is hard to trust.

Meera ships Static Variables in a result script. That is the use case worth saying.

Static Variables miss — using marks without $. Fix it before you talk about advanced PHP.

Static Variables is not a lonely heading. Meera ties it to $marks = 72.

One breath for Static Variables, then $marks = 72, then using marks without $. Sit down.

Exam tip

Say Static Variables in one breath, then $name = 'Asha';, then using marks without $.

Example

<?php
// Static Variables
$scores = [80, 90, 70];
$avg = array_sum($scores) / count($scores);
echo "avg=" . number_format($avg, 1) . "\n";
foreach ($scores as $s) {
  if ($s >= 80) echo "high: $s\n";
}

Static Variables: scores array, print avg, then high marks. Say the output.

Short notes

  • DefStatic Variables — Meera uses it for $marks = 72 in a result script.
  • RuleStatic Variables → $name = 'Asha';.
  • RememberStatic Variables + the PHP runtime (a result script).
  • UseStatic Variables in a result script ($marks = 72).
  • TrapStatic Variables — using marks without $.
  • ExStatic Variables → $marks = 72.

Questions

1

Meera asks: why does Static Variables exist? Use $marks = 72.

2

Name one PHP screen/job that needs Static Variables.

3

How do you catch using marks without $?

4

Dry-run $name = 'Asha'; and say the result.

Previous← Type HintingNextMySQLi CONNECT →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.