Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions ext/intl/collator/collator_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ PHP_FUNCTION( collator_get_attribute )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;

if (!co || !co->ucoll) {
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
"Object not initialized", 0 );
zend_throw_error(NULL, "Object not initialized");

RETURN_THROWS();
}

value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error getting attribute value" );

Expand All @@ -64,6 +73,15 @@ PHP_FUNCTION( collator_set_attribute )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;

if (!co || !co->ucoll) {
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
"Object not initialized", 0 );
zend_throw_error(NULL, "Object not initialized");

RETURN_THROWS();
}

/* Set new value for the given attribute. */
ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
Expand All @@ -87,6 +105,15 @@ PHP_FUNCTION( collator_get_strength )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;

if (!co || !co->ucoll) {
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
"Object not initialized", 0 );
zend_throw_error(NULL, "Object not initialized");

RETURN_THROWS();
}

/* Get current strength and return it. */
RETURN_LONG( ucol_getStrength( co->ucoll ) );
}
Expand All @@ -109,6 +136,15 @@ PHP_FUNCTION( collator_set_strength )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;

if (!co || !co->ucoll) {
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
"Object not initialized", 0 );
zend_throw_error(NULL, "Object not initialized");

RETURN_THROWS();
}

/* Set given strength. */
ucol_setStrength( co->ucoll, strength );

Expand Down
42 changes: 42 additions & 0 deletions ext/intl/tests/collator_attribute_unconstructed.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Collator attribute and strength methods on unconstructed object
--EXTENSIONS--
intl
--FILE--
<?php
class C extends Collator {
public function __construct() {
// omitting parent::__construct();
}
}
$c = new C();

try {
var_dump($c->getAttribute(Collator::NUMERIC_COLLATION));
} catch (Error $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}

try {
var_dump($c->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON));
} catch (Error $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}

try {
var_dump($c->getStrength());
} catch (Error $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}

try {
var_dump($c->setStrength(Collator::SECONDARY));
} catch (Error $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}
?>
--EXPECT--
Error: Object not initialized
Error: Object not initialized
Error: Object not initialized
Error: Object not initialized
Loading