2014-08-21 11:58
浏览 20


I have a PHP webpage containing several php scripts. In the first script I create an object, which is needed by all scripts. In general I want to avoid globals, so how can I send an object from one script to another script?

My first point of thought was to use $_SERVER['object']=$myobject. But I realized that this is not working. So I'm looking for another solution. In the past years I used PHP_SELF, but that was used in forms. In this case I do not have any forms and this object is created before a session is started and will be uses also outside sessions. Is there another option?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douye8500
    douye8500 2014-08-21 12:10

    why don't you create a page , call it Shared.php or whatever , create the object inside it , and use require("Shared.php"); in each of the needed scripts ? require will include this object defined in Shared.php

    点赞 评论