> On May 29, 2018, at 5:03 PM, John <john.iliffe@xxxxxxxxx> wrote: > > On Tue, 2018-05-29 at 16:38 -0700, Jeff wrote: >>> On May 29, 2018, at 1:25 PM, John <john.iliffe@xxxxxxxxx> wrote: >>> >>> On Tue, 2018-05-29 at 22:06 +0200, Christoph M. Becker wrote: >>>> On 29.05.2018 at 16:18, John wrote: >>>> >>>>> Thanks for your reply Christoph. From your and other comments it >>>>> appears >>>>> that I >>>>> can't do what I was trying to do. >>>>> >>>>> On the one hand, it is satisfying that I wasn't making a mistake; on the >>>>> other, >>>>> I sure wish there was a way to avoid passing all these variables in >>>>> PHP! In >>>>> a >>>>> way it makes the "function" command far less valuable than it should be! >>>> >>>> On the contrary, I'd say! If I see a variable inside a function body, I >>>> almost immediately know that it is a local variable or a function >>>> parameter (or a superglobal), unless there is a global “declaration”. >>>> Even better, each time I add a global “declaration”, I'm reminded to >>>> think of a better way to express myself, and if I see a lengthy list of >>>> globals, I know that the code will be hard to maintain. See also >>>> <http://wiki.c2.com/?GlobalVariablesAreBad>. >>>> >>> >>> Well, it's certainly one point of view, and I don't disagree with most of >>> it. >>> >>> On the other hand, I would assume that the word "global" really means >>> global, >>> that is, in scope to the entire script, and I think most programming >>> languages >>> with which I have worked follow this convention. >>> >>> It is necessary to be aware of the programme structure and define variables >>> in >>> the proper scope - if the variable is local, then define it in local scope, >>> if >>> it is required throughout the script or programme, then put it in global >>> scope. >>> >>> The reference you gave mentions that conflicts could occur with variable >>> names >>> within a a function but I think this would simply hide the conflicting >>> global >>> (but I confess to being unsure about that in PHP). >>> >>> For full disclosure here, I am not a programmer and never have been; simply >>> run >>> a web site for a small publishing company and I am the sysadmin, web >>> designer, >>> operator, network specialist and you name it. I worked in IT in operations >>> for >>> many years on IBM mainframes before I retired; I'm in my late 70's now and >>> all >>> this is simply to keep me out of trouble! There's nothing on earth more >>> terrifying that a bored retiree with time on his hands. >>> >>> Thanks again. >>> >>> John >> >> Hi again; >> We have some things in common, but not including employment. >> I am a developer who does this for a hobby and to maintain my own >> portfolio site and another for a stained glass artist friend. >> >> This may be off, but as I understand it, in c programming, if you compile a >> separate >> source file with its own globals, those globals aren’t necessarily global to >> the whole >> program in which the compiled source file is included. >> >> But what I do when I have a lot of otherwise globals, as in procedural code, I >> create >> as class definition and create private static variable for reference. These >> variables >> can be initiated and/or configured with the use of a constructor function >> inside the >> class definition. The idea is that global variables are exposed to all sorts >> of scripts >> and functions and can be altered or used by functions and code that shouldn’t >> be >> using and/or altering them. But, I have been programming self processing >> html/php >> files that present and manage user interface elements. So one class definition >> can >> be used to service all requests, for the most part. The class definition, can >> in turn, >> include or require other script files to supplement. These supplemental files >> can >> contain “global” variable definitions with default initialization. These >> cannot be altered >> accept through brute force rewrite of the script file they are defined in. >> >> http://php.net/manual/en/book.classobj.php >> >> I hope this is useful. >> Jeff K >> > Thanks for the suggestion Jeff. It does sound workable in what I am doing here, > which is basically reporting, where the report format varies depending on > characteristics of the data, but the data is being read in a loop from core > database code that is the mainline of the script. Since several different > formats can occur on succeeding pages I wrote a separate function. That is, > read the data, decide the report format, and call the appropriate page routine. > > It is going to take a while for me to fully understand the reference that you > sent but it does look like the solution, in this case anyway. > > My sincere thanks for your assistance and patience. > > John > ========================================= I am glad to be able to share my experience. Jeff K. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php