Permalink
Browse files

Provide class for stopping writing to undeclared properties

Summary:
This generalizes D3607 and future D3601.

It should be trait since PHP 5.4.

Test Plan: Will use it.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, btrahan

Differential Revision: https://secure.phabricator.com/D3618
  • Loading branch information...
1 parent 579c231 commit ad687ffc3de39ce0f7676f37ba93e79c7e256f64 vrana committed Oct 4, 2012
Showing with 29 additions and 0 deletions.
  1. +1 −0 src/__phutil_library_map__.php
  2. +28 −0 src/object/Phobject.php
View
1 src/__phutil_library_map__.php
@@ -65,6 +65,7 @@
'LinesOfALargeFile' => 'filesystem/linesofalarge/LinesOfALargeFile.php',
'LinesOfALargeFileTestCase' => 'filesystem/linesofalarge/__tests__/LinesOfALargeFileTestCase.php',
'MFilterTestHelper' => 'utils/__tests__/MFilterTestHelper.php',
+ 'Phobject' => 'object/Phobject.php',
'PhutilAWSEC2Future' => 'future/aws/PhutilAWSEC2Future.php',
'PhutilAWSException' => 'future/aws/PhutilAWSException.php',
'PhutilAWSFuture' => 'future/aws/PhutilAWSFuture.php',
View
28 src/object/Phobject.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * Copyright 2012 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+abstract class Phobject {
+
+ public function __set($name, $value) {
+ throw new DomainException(
+ "Attempted write to undeclared property ".get_class($this)."::\$$name. ".
+ "This is an application error, please report it at ".
+ "https://secure.phabricator.com/maniphest/task/create/");
+ }
+
+}

0 comments on commit ad687ff

Please sign in to comment.