Skip to content

Instantly share code, notes, and snippets.

View tim-cotten's full-sized avatar

Tim Cotten tim-cotten

View GitHub Profile
@tim-cotten
tim-cotten / php_bugs_6f.php
Created March 5, 2021 19:29
PHP Bugs: Property Problems (Example F)
<?php
// ... $desc should be a JSON string ...
if (!empty($desc)) {
try {
$desc_obj = json_decode($desc);
if (!is_object($desc_obj)) {
throw new Exception();
}
@tim-cotten
tim-cotten / php_bugs_6e.php
Created March 5, 2021 19:17
PHP Bugs: Property Problems (Example E)
<?php
// ... $desc should be a JSON string ...
if (!empty($desc)) {
$desc_obj = json_decode($desc);
$action = $desc_obj->action;
$reasons = explode(',', $desc_obj->reasons);
// ... parsing logic for $reasons ...
}
@tim-cotten
tim-cotten / php_bugs_6d.php
Created March 5, 2021 19:06
PHP Bugs: Property Problems (Example D)
<?php
namespace Shop;
require_once('/app/cottenio/code/autoloader.php');
class DropShip
{
public $shopcode;
public $name;
public $postalcode;
<?php
$shop = new Shop\DropShip($shop_id);
if ($shop) {
$code = $shop->shopcode;
$shop = $shop->shopname;
$zip = $shop->postalcode;
$phone = $shop->phone;
@tim-cotten
tim-cotten / php_bugs_6b.php
Created March 5, 2021 18:43
PHP Bugs: Property Problems (Example B)
<?php
try
{
$response = $client->track($request);
if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR')
{
if (isset($response->TrackDetails)) {
$return[0] = $response->TrackDetails->StatusCode;
$return[1] = $response->TrackDetails->StatusDescription;
@tim-cotten
tim-cotten / php_bugs_6_1.php
Created March 5, 2021 18:29
PHP Bugs: Property Problems (Proof 1)
<?php
$bird = new stdClass();
$bird->name = "Mockingbird";
$tail = new stdClass();
$tail->color = "Brown";
$tail->type = null;
$bird->tail = $tail;
@tim-cotten
tim-cotten / php_bugs_6a.php
Created March 5, 2021 16:45
PHP Bugs: Property Problems (Example A)
<?php
try
{
$response = $client ->track($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
{
$return[0]=$response->TrackDetails->StatusCode;
$return[1]=$response->TrackDetails->StatusDescription;
@tim-cotten
tim-cotten / php_bugs_5g.php
Created March 5, 2021 13:37
PHP Bugs: Arrays Don't Like Undefined Offsets (Example G)
<?php
if (!empty($img)) {
$tmg = pathinfo(str_replace('\\', '/', $img));
$img = $tmg['basename'];
}
@tim-cotten
tim-cotten / php_bugs_5f.php
Created March 5, 2021 13:03
PHP Bugs: Arrays Don't Like Undefined Offsets (Example F)
<?php
if (!empty($img)) {
$tmg = explode("/", $img);
$img = $tmg[3];
}
@tim-cotten
tim-cotten / php_bugs_5e.php
Created March 5, 2021 12:56
PHP Bugs: Arrays Don't Like Undefined Offsets (Example E)
<?php
// Set relative product URLs
foreach ($products as &$product) {
$url = "&product_id={$product['id']}";
$name = explode(" -- ", $product['name']); // like: Chocolates -- 587
$url .= "&name={$name[0]}";
if (!empty($name[1])) {
$name[1] = str_pad($name[1], 8, "0", STR_PAD_LEFT); // format as 00000587