开发者

Can I create an instance of an object while declaring it?

开发者 https://www.devze.com 2023-03-14 08:35 出处:网络
Given this java snippet: public class PDFObject { /** the NULL PDFObject */ public static final PDFObject nullObj = new PDFObject(null, NULL, null);

Given this java snippet:

public class PDFObject {

/** the NULL PDFObject */
public static final PDFObject nullObj = new PDFObject(null, NULL, null);

..
}

How can I convert this into PHP? Is it possible to create an instance of an object while still declaring it?

Source File: http://code.google.com/p/txtreader开发者_如何学JAVApdf/source/browse/trunk/txtReader/src/com/sun/pdfview/PDFObject.java


This is the workaround you would need in PHP:

class PDFObject {

/** the NULL PDFObject */
public static $nullObj = NULL;

..
}

PDFObject::$nullObj = new PDFObject(null, NULL, null);

Normally expression assignments are done in the constructor. But since you want a static class attribute, you will need to resort to inline/global code like that.

0

精彩评论

暂无评论...
验证码 换一张
取 消