开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜