Skip to content

Prevent auto-creation of public properties on your classes

License

Notifications You must be signed in to change notification settings

CJDennis/class-protection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

class-protection

Prevent auto-creation of public properties on your classes

Usage:

<?php
require_once 'class_protection.class.php';

class MyClass {
  use ClassProtection;

  // Remainder of class code
}

It is now no longer possible to dynamically create new public properties at run-time from either inside or outside the class MyClass, but any existing public properties can still be accessed and changed. All public properties must now be declared before they're used, just like protected and private properties.

That's it!

One caveat: unset() can still be called on public properties and delete them from the object. It's best to completely avoid using public properties for a robust class with locked-down behaviour.

About

Prevent auto-creation of public properties on your classes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages