Martian Defense NoteBook
  • Martian Defense Notebook
  • Training and Career
    • Keeping it Real for Beginners
    • Reading and Repos
    • Media
    • Guides
      • Cybersecurity Roadmaps
      • Cybersecurity Training Topics
      • AppSec Training Pathway
      • Interview Checklist
    • Platforms
      • General
      • Offensive Security
      • Defensive Security
      • CTF Sites
      • Live Vulnerable Sites
    • Entrepreneurship Roadmaps
      • Consulting
      • Starting a Business
  • Technical Resources
    • Offensive-Cybersecurity
      • Application Security
      • General
      • Recon + OSINT
      • Infrastructure Pentesting
      • Cloud Pentesting
      • Wordlists
      • Social Engineering
      • Mobile Pentesting
      • Container Security
      • Blockchain
    • Defensive-Cybersecurity
    • General Cybersecurity
      • Cybersecurity Operating Systems
    • Coding/Programming
    • Reverse Engineering
    • AI and ML
  • Notes
    • Product Security Engineering
      • DevSecOps
        • Docker
          • How to Dockerize Applications with Docker Compose (Using SQLite and Flask)
      • SAST/SCA
        • How to setup a GitHub Action for Code Security analysis
        • JavaScript Security Analysis
        • Java Security 101
        • Tools
        • CodeQL for Beginners
      • Product Security Hardening
      • Threat Modeling
      • PHP Security
    • AppSec Testing
      • Checklists
        • WEB APP PENTESTING CHECKLIST
        • API Testing Checklist
        • Android Pentesting Checklist
        • IoS Pentesting Checklist
        • Thick Client Pentesting Checklist
        • Secure Code Review Checklist
      • Targeted Test Cases
        • Part 1
        • Part 2
      • Common Web Attack and Prevention List
      • Ports and associated Vectors
      • DNS
      • Web Tools
      • Command Injection Testing
      • JWTs and JSON
    • Security Research
      • Publishing CVEs
      • Threat Intelligence
      • Shodan Dork Cheatsheet
      • Github Dorks
      • Bug Bounty
        • Bug Bounty Programs
      • Forums
    • Coding/Programming
      • Secure Coding Practices Checklist
      • JavaScript
      • Python
        • Quick Notes
        • Python Basics for Pentesters
        • Python Snippets
        • XML Basics with Python
      • Golang
        • Theory
        • Security
        • Modules
        • Entry Points
        • File Forensics
        • Cryptography and Encoding
        • Golang Snippets
      • PHP
        • Setup
        • Syntax
        • Variables and Data Types
        • Control Structures
        • Arrays
        • Functions
        • OOP Concepts
        • Database Integration
        • Handling HTTP Methods
        • Session Management
        • File Uploads
        • Email Function
        • Error Handling
        • Advanced Topics and Best Practices
    • Network Security
      • Domain Trust Enumeration
      • Bleeding Edge Vulnerabilities
      • Post-Exploitation
      • Access Control Lists and Entries (ACL & ACE)
      • Credentialed Enumeration
      • Password Attacks
        • Internal Password Spraying
        • Remote Password Attacks
        • Linux Local Password Attacks
        • Windows Local Password Attacks
        • Windows Lateral Movement
      • PowerView
      • Pivoting, Tunneling and Forwarding
        • Advanced Tunneling Methods
        • Dynamic Port Forwarding (SSH + Socks)
        • Port Forwarding Tools
        • SoCat
      • Linux Privilege Escalation
      • Windows Privesc
        • OS Attacks
        • Windows User Privileges
        • Windows Group Privileges
        • Manual Enumeration
        • Credential Theft
      • Kerberos Attacks
        • Kerberos Quick Reference Sheet
    • Cloud Security Testing
    • Defensive Security
      • Splunk
        • Basic Queries
        • Dashboards
      • Forensics
        • Volatility
      • WireShark filters
    • Governance, Risk, Compliance
      • Vulnerability Management Lifecycle
    • Capture-the-Flag Training
      • Vulnerable Machine Checklist
      • Reverse Engineering Checklist
      • Mobile Checklist
      • Forensics Checklist
      • Binary Exploitation
      • Cryptography Checklist
    • Reporting
    • PowerShell
    • Linux Basics
    • Basic IT Tasks
  • Digital Privacy and Hygiene
    • Personal Information Removal Services
    • De-Googling Android
    • DNS Services
    • Privacy References
    • Opsec
  • RedPlanet Labs
    • PyGOAT
    • OWASP Juice Shop
Powered by GitBook
On this page
  • Variables
  • Data Types
  1. Notes
  2. Coding/Programming
  3. PHP

Variables and Data Types

One of the first things to understand when learning any programming language are variables and data types.

Variables

In PHP, variables are declared with a dollar sign $ followed by the variable's name. PHP is a loosely typed language, which means that you don't have to declare the data type of a variable when you create one. Here's an example:

<?php
$name = "Alice"; // This is a string.
$age = 25; // This is an integer.
$weight = 65.5; // This is a float.
$isStudent = true; // This is a boolean.
?>

Data Types

PHP supports several data types, which define what kind of data a variable can hold:

  1. String: A sequence of characters, like "Hello, World!". Strings are defined by enclosing the text in quotes:

    <?php
    $string = "Hello, World!";
    echo $string; // Outputs: Hello, World!
    ?>
  2. Integer: A non-decimal number. Integers can be positive or negative:

    <?php
    $integer = 42;
    echo $integer; // Outputs: 42
    ?>
  3. Float (or double): A number with a decimal point or a number in exponential form:

    <?php
    $float = 3.14;
    echo $float; // Outputs: 3.14
    ?>
  4. Boolean: Represents two possible states: TRUE or FALSE:

    <?php
    $boolean = true;
    echo $boolean; // Outputs: 1 (for TRUE)
    ?>
  5. Array: An ordered map (a type of data structure that pairs keys with values):

    <?php
    $array = array("Alice", "Bob", "Charlie");
    print_r($array); // Outputs: Array ( [0] => Alice [1] => Bob [2] => Charlie )
    ?>
  6. Object: Instances of classes, which PHP allows you to create so that you can use objects to manage and organize your code (discussed in detail in a later section):

    <?php
    class Car {
        function Car() {
            $this->model = "VW";
        }
    }
    $herbie = new Car(); // create an object
    echo $herbie->model; // show object properties
    ?>
  7. NULL: A special data type representing a variable with no value. A variable of data type NULL is a variable that has no value assigned to it:

    <?php
    $var = NULL;
    var_dump($var); // Outputs: NULL
    ?>
PreviousSyntaxNextControl Structures

Last updated 5 months ago