File tree Expand file tree Collapse file tree 3 files changed +16
-15
lines changed Expand file tree Collapse file tree 3 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,14 @@ impl Enum {
190190 ///
191191 /// A reference to ZObj representing the enum case, or an error if the case
192192 /// doesn't exist
193+ ///
194+ /// # Safety
195+ ///
196+ /// This function is marked as unsafe because the underlying `zend_enum_get_case`
197+ /// function may cause a SIGSEGV (segmentation fault) when the case doesn't exist.
198+ /// Even though this method attempts to check for null and return an error instead,
199+ /// there might still be scenarios where the PHP internal function behaves unpredictably.
200+ /// Callers must ensure the enum and case name are valid before calling this function.
193201 pub fn get_case < ' a > ( & self , case_name : impl AsRef < str > ) -> crate :: Result < & ' a ZObj > {
194202 unsafe {
195203 let ce = self . as_class_entry ( ) . as_ptr ( ) as * mut _ ;
@@ -225,6 +233,14 @@ impl Enum {
225233 ///
226234 /// A mutable reference to ZObj representing the enum case, or an error if
227235 /// the case doesn't exist
236+ ///
237+ /// # Safety
238+ ///
239+ /// This function is marked as unsafe because the underlying `zend_enum_get_case`
240+ /// function may cause a SIGSEGV (segmentation fault) when the case doesn't exist.
241+ /// Even though this method attempts to check for null and return an error instead,
242+ /// there might still be scenarios where the PHP internal function behaves unpredictably.
243+ /// Callers must ensure the enum and case name are valid before calling this function.
228244 pub fn get_mut_case < ' a > ( & mut self , case_name : impl AsRef < str > ) -> crate :: Result < & ' a mut ZObj > {
229245 unsafe {
230246 let ce = self . as_class_entry ( ) . as_ptr ( ) as * mut _ ;
Original file line number Diff line number Diff line change @@ -112,16 +112,4 @@ fn test_enum_from_name(module: &mut Module) {
112112
113113 Ok :: < _ , phper:: Error > ( zobj)
114114 } ) ;
115-
116- // Test getting a non-existent case
117- module. add_function ( "test_enum_get_invalid_case" , |_args| {
118- let pure_enum = Enum :: from_name ( "IntegrationTest\\ PureEnum" ) ;
119-
120- // Try to get a non-existent enum case
121- phper:: ok ( match pure_enum. get_case ( "NONEXISTENT" ) {
122- Ok ( _) => false ,
123- Err ( phper:: Error :: EnumCaseNotFound ( _) ) => true ,
124- Err ( _) => false ,
125- } )
126- } ) ;
127115}
Original file line number Diff line number Diff line change 7171assert_eq ($ red_case ->name , 'RED ' , 'Should be the RED case ' );
7272assert_eq ($ red_case ->value , 'FF0000 ' , 'RED value should be FF0000 ' );
7373assert_eq ($ red_case , IntegrationTest \StringEnum::RED , 'Should be equal to the enum case ' );
74-
75- // Test error handling when retrieving invalid case
76- assert_true (test_enum_get_invalid_case (), 'Should return an error for non-existent case ' );
You can’t perform that action at this time.
0 commit comments