2017 © Pedro PelĂĄez
 

library struct

image

lpeltier/struct

  • Wednesday, September 28, 2016
  • by L-P
  • Repository
  • 0 Watchers
  • 0 Stars
  • 64 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 3 % Grown

The README.md

struct

struct-like trait for PHP., (*1)

Usage

Create a struct by using the struct trait in a class and declaring public properties. You can then read and write those properties using the arrow (->) operator. Any attempt to access an undefined, protected, or private property will result in an exception.
You can also use the constructor to set all properties at once., (*2)

Example:, (*3)

<?php

use lpeltier\Struct;

class Foo
{
    use Struct;

    public $foo = 'default';
    public $bar;
}

$foo = new Foo(['bar' => 0x2A]);

var_dump($foo->foo); // 'default'
var_dump($foo->bar); // 42
var_dump($foo->baz); // throws an exception

Why

PHP automatically creates unknown properties when you set them, without even throwing a notice. This can lead to one those silly bugs that takes ages to find because you wrote 'nuw' instead of 'num'., (*4)

The Versions

28/09 2016

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

28/09 2016

2.0.1

2.0.1.0

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

15/07 2015

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

15/07 2015

0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires