2016-11-27 22 views
7

मेरे पास निम्न कोड है, जहां मुझे त्रुटि मिलती है "PHP घातक त्रुटि: निरंतर अभिव्यक्ति में अमान्य ऑपरेशन होते हैं"। जब मैं कन्स्ट्रक्टर में चर परिभाषित करता हूं तो यह ठीक काम करता है। मैं लैरवेल ढांचे का उपयोग कर रहा हूँ।निरंतर अभिव्यक्ति में अमान्य संचालन

<?php 

namespace App; 

class Amazon 
{ 
    protected $serviceURL = config('api.amazon.service_url'); 

    public function __construct() 
    { 
    } 

} 
+0

आप उस बिंदु पर कार्यों का उपयोग नहीं कर सकते, निर्माता – RST

+0

आप की जरूरत पर ले जाते हैं निर्माण() फ़ंक्शन के अंदर serviceURL मान असाइन करें –

उत्तर

11

के रूप में वर्णित here

Class member variables are called "properties". You may also see them referred to using other terms such as "attributes" or "fields", but for the purposes of this reference we will use "properties". They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

एक ही तरीका है कि आप इस काम कर सकते हैं: -

<?php 

namespace App; 

class Amazon 
{ 
    protected $serviceURL; 

    public function __construct() 
    { 
    $this->serviceURL = config('api.amazon.service_url'); 
    } 
} 
0

कक्षा गुणों को आरंभ करने की अनुमति नहीं है। आपको प्रारंभकर्ता को कन्स्ट्रक्टर में ले जाना चाहिए।

संबंधित मुद्दे