PHP - strange syntax errors using parentheses inside an array of classes

I have a simple code:

        class o99_custom_fields {
            /**
            * @var  string  $prefix  The prefix for storing custom fields in the postmeta table
            */
            var $prefix = 'o99_';
            /**
            * @var  array  $customFields  Defines the custom fields available
            */
            var $customFields = array(

                array(
                    "name"          => "some_name",
                    "title"         => "some Title",
                    "description"   => "Some Desctiption Text",
                    "type"          => "k_upload",
                    "scope"         =>  array( "post" ),
                    "capability"    => "edit_post"
                ),

                array(
                    "name"          => "some_name2",
                    "title"         => "some Title",
                    "description"   => "Some Desctiption Text",
                    "type"          => "k_upload",
                    "scope"         =>  array( "post" ),
                    "capability"    => "edit_post"
                ),

                array(
                    "name"          => "some_name3",
                    "title"         => "some Title",
                    "description"   => "",
                    "type"          => "k_textarea",
                    "scope"         =>  array( "post" ),
                    "capability"    => "edit_post"
                ),
            );
... more functions and more code ...
    } // End Class

And everything looks fine

The problem starts when I try to change some array values ​​and put them in brackets ()

eg:

array(
                "name"          => "some_name",
                "title"         => __("some Title","text_domain"),// ERROR OCCUR
                "description"   => "Some Desctiption Text",
                "type"          => "k_upload",
                "scope"         =>  array( "post" ),
                "capability"    => "edit_post"
            ),

Error message:

Parse error: syntax error, unexpected '(', expecting ')' in E:\my_path\myfile.php on line 18

Please note that this is not related to the function __()( standard Wordpress translation function ), and the error is not related to the function, but SYNTAX. (I use this hundreds of times in the past without any problems - and in this case also, _x()and _e()fail at the same syntax error ..)

All my brackets are closed, I checked and checked again, and if I am not completely blind, I would say that everything is in order, but I still get this error, regardless of where I put the brackets inside this class.

: :

class o99_custom_fields {
                /**
                * @var  string  $prefix  The prefix for storing custom fields in the postmeta table
                */
                var $prefix = 'o99_';
                /**
                * @var  array  $customFields  Defines the custom fields available
                */
                var $dummy_strings = array (
__('x1','text_domain'),
__('x2','text_domain'),
);

    ... more functions and more code ...
        } // End Class

, SYNTAX, . php (UTF-8 )

- // .

I:

..

/**
* PHP 4 Compatible Constructor
*/
function o99_custom_fields() { $this->__construct(); }
/**
* PHP 5 Constructor
*/

function __construct() {
    add_action( 'admin_menu', array( &$this, 'createCustomFields' ) );
    add_action( 'save_post', array( &$this, 'saveCustomFields' ) );
}
+4
2

, , , , .

:

class SomeClass{
...
private $myProp0 = array(); //OK
private $myProp1 = array('foo' => 'bar', 'foooo' => 'baaar'); //OK
private $myProp2 = null; //OK
private $myProp3 = 10; //OK
private $myProp4 = "something"; //OK
private $myProp5 = __('translate me') // NOT OK
...
}

- (, ), .

- :

function someFunction($x, $y){
    return "mouahahaha";
}

class SomeClass{
    private $something = array();

    public function __construct(){
        $this->something = array(
            'somekey1' => 'foobar',
            'somekey2' => someFunction("foo", "bar"),
        );
    }
}

, .

:

class o99_custom_fields {
        /**
        * @var  string  $prefix  The prefix for storing custom fields in the postmeta table
        */
        var $prefix = 'o99_';
        /**
        * @var  array  $customFields  Defines the custom fields available
        */
         private $customFields = array();
        /**
        * PHP 4 Compatible Constructor
        */
        function o99_custom_fields() { $this->__construct(); }
        /**
        * PHP 5 Constructor
        */

        public function __construct() {

         $this->customFields =  array(

            array(
            "name"          => "some_name",
            "title"         => __("some Title","text_domain"),// NO ERROR NOW
            "description"   => "Some Desctiption Text",
            "type"          => "k_upload",
            "scope"         =>  array( "post" ),
            "capability"    => "edit_post"
        ),
       );
       // Do your other construct things 
     } // END __construct
+6

, ; , :

[...] , , .

i., __() . , , , . ideone

function __($param1,$param2){}

$customFields = array(
   array(
     "name" => "some_name",
      "title" => __("some Title","text_domain"),// ERROR OCCUR
      "description" => "Some Desctiption Text",
      "type" => "k_upload",
      "scope" => array( "post" ),
      "capability" => "edit_post"
    ),
);

; var ( public)

+4

All Articles