diff options
| author | Marcus Boerger <helly@php.net> | 2003-03-03 11:10:30 +0000 |
|---|---|---|
| committer | Marcus Boerger <helly@php.net> | 2003-03-03 11:10:30 +0000 |
| commit | 326b793fafda3850a9123f65601bb4aab0919018 (patch) | |
| tree | 4d1692c9adab0cf8414d56431f9e7658a1b14dde /tests/classes | |
| parent | 3f8c08b5e1c30fc6e6a918af5f5cdc709f11d691 (diff) | |
| download | php-git-326b793fafda3850a9123f65601bb4aab0919018.tar.gz | |
Adding tests for final methods
Diffstat (limited to 'tests/classes')
| -rw-r--r-- | tests/classes/abstract_final.phpt | 16 | ||||
| -rw-r--r-- | tests/classes/final.phpt | 31 | ||||
| -rw-r--r-- | tests/classes/final_abstract.phpt | 16 | ||||
| -rw-r--r-- | tests/classes/final_redeclare.phpt | 28 |
4 files changed, 91 insertions, 0 deletions
diff --git a/tests/classes/abstract_final.phpt b/tests/classes/abstract_final.phpt new file mode 100644 index 0000000000..7aac02615d --- /dev/null +++ b/tests/classes/abstract_final.phpt @@ -0,0 +1,16 @@ +--TEST-- +A final method cannot be abstract +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class fail { + abstract final function show(); +} + +echo "Done\n"; // Shouldn't be displayed +?> +--EXPECTF-- + +Fatal error: Cannot use the final modifier on an abstract class member in %s on line %d diff --git a/tests/classes/final.phpt b/tests/classes/final.phpt new file mode 100644 index 0000000000..733adf2e84 --- /dev/null +++ b/tests/classes/final.phpt @@ -0,0 +1,31 @@ +--TEST-- +A method may be redeclared final +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class first { + function show() { + echo "Call to function first::show()\n"; + } +} + +$t = new first(); +$t->show(); + +class second extends first { + final function show() { + echo "Call to function second::show()\n"; + } +} + +$t2 = new second(); +$t2->show(); + +echo "Done\n"; +?> +--EXPECTF-- +Call to function first::show() +Call to function second::show() +Done
\ No newline at end of file diff --git a/tests/classes/final_abstract.phpt b/tests/classes/final_abstract.phpt new file mode 100644 index 0000000000..37aa0bee8f --- /dev/null +++ b/tests/classes/final_abstract.phpt @@ -0,0 +1,16 @@ +--TEST-- +A final method cannot be abstract +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class fail { + final abstract function show(); +} + +echo "Done\n"; // Shouldn't be displayed +?> +--EXPECTF-- + +Fatal error: Cannot use the final modifier on an abstract class member in %s diff --git a/tests/classes/final_redeclare.phpt b/tests/classes/final_redeclare.phpt new file mode 100644 index 0000000000..bdf34a149a --- /dev/null +++ b/tests/classes/final_redeclare.phpt @@ -0,0 +1,28 @@ +--TEST-- +A final method may not be overwritten +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class pass { + final function show() { + echo "Call to function pass::show()\n"; + } +} + +$t = new pass(); +$t->show(); + +class fail extends pass { + function show() { + echo "Call to function fail::show()\n"; + } +} + +echo "Done\n"; // Shouldn't be displayed +?> +--EXPECTF-- +Call to function pass::show() + +Fatal error: Cannot override final method pass::show() in %s on line %d |
