Skip to content

Instantly share code, notes, and snippets.

@heiglandreas
heiglandreas / Date.php
Last active July 4, 2018 19:06
A plain Date-Object without time-information – somehow
<?php
/*
* Copyright (c) Andreas Heigl <[email protected]>
*
* Licensed under the MIT License. See LICENSE.md file in the project root
* for full license information.
*/
namespace Org_Heigl\Date;
@heiglandreas
heiglandreas / datetime.php
Created September 11, 2018 14:01
Add minutes to a datetime
$dt = new DateTimeImmutable();
$minute = new DateInterval('PT1M');
$dt = $dt->add($minute);
@heiglandreas
heiglandreas / example1.php
Created January 14, 2019 20:09
Different Scopes for reading and writing properties
<?php
class Foo
{
// when there are two visibility declarations following one another
// the first one describes reading, the second one writing.
// If it's only one declaration it is used for reading *and* writing
// So this can be read publicly but only this class can write to the property.
public private int $int;
@heiglandreas
heiglandreas / CallInPHP74.php
Last active January 24, 2021 13:27
Functions that take faulty parameters without notice in PHP7.4 but raise a type-error in PHP8
<?php
/**
* This file reads the previously created file and executes the listed function calls via eval.
* As eval throws up when something goes south I needed to exclude some calls, where pass-by-reference is used
* This script will then check whether a warning is raised or not and if not, add the function call to the file
* "problematicFunctionCalls" and the function itself to the "problematicFunctions" file.
*/
$wasError = false;
function myErrorHandler(int $errno , string $errstr , ?string $errfile = null , ?int $errline = null , ?array $errcontext = [] ): bool
@heiglandreas
heiglandreas / DateInterval.php
Last active September 2, 2021 06:17
Get difference between two dates including a one-month difference when both dates are on the last day of a month regardles the actual date
<?php
namespace Org_Heigl\Date;
class DateInterval extends \DateInterval
{
public static function fromDates(DateTimeInterface $a, DateTimeInterface $b) : \DateInterval
{
$first = $a;
@heiglandreas
heiglandreas / servers.md
Last active October 30, 2021 17:33
Websites to check for Webserver Security
@heiglandreas
heiglandreas / Code executed
Last active April 9, 2022 20:30
PHP DOM oddities
<?php
declare(strict_types=1);
$string = <<<'EOF'
Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">
Foo
EOF;
@heiglandreas
heiglandreas / demo.php
Created April 11, 2022 07:55
Never use "unicode" as Content-Type
<?php
declare(strict_types=1);
$string = <<<'EOF'
Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">
Foo
EOF;
<?php
class ClassToTestA
{
public function __construct(private ClockInterface $clock) {}
public function do(): void
{
$a = $this->clock->now();
sleep(6);
@heiglandreas
heiglandreas / ci-fail.yml
Last active March 26, 2023 13:03
Patch-Coverage as GitHub Action
jobs:
patch-coverage:
# Fail when untested lines are found
steps:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
tools: "phive"
coverage: "xdebug"
- name: "Install tools"