File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / Zend / tests / traits / property001.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:36 2012 UTC (12 years, 1 month ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, HEAD
php 5.4.3+patches

--TEST--
Potentially conflicting properties should result in a strict notice. Property use is discorage for traits that are supposed to enable maintainable code reuse. Accessor methods are the language supported idiom for this.
--FILE--
<?php
error_reporting(E_ALL);

trait THello1 {
  private $foo;
}

trait THello2 {
  private $foo;
}

echo "PRE-CLASS-GUARD-TraitsTest\n";
error_reporting(E_ALL & ~E_STRICT); // ensuring that it is only for E_STRICT

class TraitsTest {
	use THello1;
	use THello2;
}

error_reporting(E_ALL | E_STRICT);

echo "PRE-CLASS-GUARD-TraitsTest2\n";

class TraitsTest2 {
	use THello1;
	use THello2;
}

var_dump(property_exists('TraitsTest', 'foo'));
var_dump(property_exists('TraitsTest2', 'foo'));
?>
--EXPECTF--	
PRE-CLASS-GUARD-TraitsTest
PRE-CLASS-GUARD-TraitsTest2

Strict Standards: THello1 and THello2 define the same property ($foo) in the composition of TraitsTest2. This might be incompatible, to improve maintainability consider using accessor methods in traits instead. Class was composed in %s on line %d
bool(true)
bool(true)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>