PHP Classes

File: example2.php

Recommend this page to a friend!
  Classes of Jorge Castro   PHP Benchmarks   example2.php   Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Benchmarks
Evaluate the speed of PHP running different tasks
Author: By
Last change:
Date: 3 years ago
Size: 1,039 bytes
 

Contents

Class file image Download
<?php


class Invoice {
    public
int $idInvoice;
    public
DateTime $dateInvoice;
    public array
$invoiceDetails;
  
}


class
InvoiceDetail {
    public
int $idInvoiceDetail;
    public
int $idProduct;
    public
int $price; // or decimal
   
}

function
InvoiceFactory() {
    return [
'idInvoice'=>null,'dateInvoice'=>null,'invoiceDetails'=>[]];
}
function
InvoiceDetailFactory() {
    return [
'idInvoiceDetail'=>null,'idProduct'=>null,'price'=>null];
}

$obj=InvoiceFactory();
$obj['invoiceDetails']=[InvoiceDetailFactory(),InvoiceDetailFactory()];




$obj=new Invoice();
$obj->dateInvoice=new DateTime();
$obj->invoiceDetails=[new InvoiceDetail(),new InvoiceDetail()];

var_dump(unserialize(serialize($obj)));
echo
"<br>";

$obj2=objectToObject(json_decode( json_encode($obj)),'Invoice');

var_dump( $obj2);


function
objectToObject($instance, $className) {
    return
unserialize(sprintf(
       
'O:%d:"%s"%s',
       
strlen($className),
       
$className,
       
strstr(strstr(serialize($instance), '"'), ':')
    ));
}