In your first example:
PHP Code:
<?php
// incorrect:
// static function count_repeat_values( $needle,$haystack ){ /* ... */ }
// correct:
function count_repeat_values( $needle,$haystack ){ /* ... */ }
class SomeClass{
public function someFunction( $array ){
$item = 'key';
$num = count_repeat_values( $item,$array );
// now it should work just fine
}
}
in your second example:
PHP Code:
<?php
// this works just fine also.
// however:
/*
Is the function used anywhere else, outside of this class?
if so, it would be fine to define it in the global scope (as in the example above).
I think it makes more sense that way.
It doesn't _have_ to be object-oriented if there's no real reason for it to be.
*/
class SomeClass
{
static function count_repeat_values( $needle,$haystack ){ /* ... */ }
public function someFunction( $array ){
$item = 'key';
$num = SomeClass::count_repeat_values( $item,$array );
}
}
Bookmarks