Menu
CoddyTech
Course

C for PHP Developers

Move from PHP to C17: explicit types, pointers, bounded arrays, strings, ownership, structs and modular interfaces. Build a multi-file stock ledger and port two PHP programs.

PHP and C side by side

The same program in PHP and in C, from the lessons of this course.

  1. Printing and Comments

    PHP echo turns any scalar into text, double-quoted strings interpolate variables, and PHP printf even converts each argument to the type its specifier asks for. C printf converts nothing: its conversion specifiers must match the argument types, %d prints an…

    PHP
    1<?php2$value = 7;3echo "value=$value\n";
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10printf("value=%d\n",7);11return 0;12}
  2. Booleans and Branches

    PHP truthiness is broad: 0, 0.0, "", "0", null and an empty array are all false. In C a scalar zero is false and any nonzero scalar is true. A non-null pointer is true even if it points at an empty string, because a C condition never looks at the characters…

    PHP
    1<?php2$s = "";3echo $s ? "true" : "false", "\n";
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}
  3. Arrays Need Lengths

    A PHP array is an ordered map that always knows its own count(), grows on demand and keeps that count when it is passed to a function. A C array has a fixed element count, but a function array parameter is adjusted to a pointer and does not carry that count.…

    PHP
    1<?php2$a = [2, 4, 6];3echo count($a), "\n";
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}
  4. Function Arguments Are Values

    PHP passes arguments by value unless the parameter is declared with &, and that holds for arrays too: the function gets its own copy (copy on write keeps it cheap), while an object argument copies a handle to the same object. C has no & parameter mode, and…

    PHP
    1<?php2function change(int $n): void3{4    $n = 9;5}6$x = 2;7change($x);8echo $x, PHP_EOL;
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}
  5. Addresses and Dereferencing

    A PHP reference made with =& lets two names share one value, but it is not an address: there is no address arithmetic, and the value stays alive while any name still refers to it. In C &object obtains an address and *pointer accesses the pointed-to object.…

    PHP
    1<?php2$n = 2;3$alias = &$n;4$alias = 5;5echo $n, PHP_EOL;
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}
  6. Parsing with Status Results

    PHP's (int) cast and intval() quietly keep a numeric prefix, so (int) "12x" is 12, while ctype_digit, or filter_var with FILTER_VALIDATE_INT, rejects the whole string. C library parsers report status instead of throwing. sscanf reports the number of…

    PHP
    1<?php2$text = "12x";3var_dump(ctype_digit($text));
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for PHP developers

Learn C from another language

Frequently asked questions

Who is C for PHP Developers for?

For people who already write PHP and want to learn C. Each lesson starts from PHP you know and shows how C does the same thing, so you skip the beginner basics.

Do I need to know C already?

No. The course starts with your first C program. You need PHP basics: variables, conditions, loops, functions and collections.

How many lessons does C for PHP Developers have?

C for PHP Developers contains 48 interactive lessons you can complete at your own pace.

What does C for PHP Developers cover?

The course is organized into chapters covering: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, and more.

Is C for PHP Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start C for PHP Developers for free

Get started