Inheritance causing loss of variable scope???

Hello all,
I am working on a class at the moment, "Block" that has
several private variables (call them)
_color,
_x,
_y,
_parent, ...
I have a second class (BlockGenerator extends Block). In the
constructor for BlockGenerator, I call the Block constructor using
super(parent, x, y) and then I set some of the vars inherited from
the block class. I am trying to compile in strict mode but it is
causing the following error:
1119: Access of possibly undefined property _color through a
reference with static type src.game:BlockGenerator.
the error is reported on the following line in the
BlockGenerator constructor:
this._color = new BlockColor(BlockColor.PLACE_HOLDER);
I have attached a bit more sample code. Please let me know if
anyone has any insight as to why my BlockGenerator class cannot see
the internal vars inherited from the Block class.
Thanks,
Nomadic Design

Sometimes you get so wrapped up in the complexity of what you
are doing that you completely overlook the obvious.
Thank you,
Nomadic Design

Similar Messages

  • Javascript discussion: Variable scopes and functions

    Hi,
    I'm wondering how people proceed regarding variable scope, and calling
    functions and things. For instance, it's finally sunk in that almost
    always a variable should be declared with var to keep it local.
    But along similar lines, how should one deal with functions? That is,
    should every function be completely self contained -- i.e. must any
    variables outside the scope of the function be passed to the function,
    and the function may not alter any variables but those that are local to
    it? Or is that not necessary to be so strict?
    Functions also seem to be limited in that they can only return a single
    variable. But what if I want to create a function that alters a bunch of
    variables?
    So I guess that's two questions:
    (1) Should all functions be self-contained?
    (2) What if the function needs to return a whole bunch of variables?
    Thanks,
    Ariel

    Ariel:
    (Incidentally, I couldn't find any way of  marking answers correct when I visited the web forums a few days ago, so I gave up.)
    It's there...as long as you're logged in at least, and are the poster of the thread.
    What I want is to write code that I can easily come back to a few months later
    and make changes/add features -- so it's only me that sees the code, but
    after long intervals it can almost be as though someone else has written
    it! So I was wondering if I would be doing myself a favour by being more
    strict about make functions independent etc. Also, I was noticing that
    in the sample scripts that accompany InDesign (written by Olav Kvern?)
    the functions seem always to require all variables to be passed to it.
    Where it is not impractical to do so, you should make functions independent and reusable. But there are plenty of cases where it is impractical, or at least very annoying to do so.
    The sample scripts for InDesign are written to be in parallel between three different languages, and have a certain lowest-common-denominator effect. They also make use of some practices I would consider Not Very Good. I would not recommend them as an example for how to learn to write a large Javascript project.
    I'm not 100% sure what you mean by persistent session. Most of my
    scripts are run once and then quit. However, some do create a modeless
    dialog (ie where you can interface with the UI while running it), which
    is the only time I need to use #targetengine.
    Any script that specifies a #targetengine other than "main" is in a persistent session. It means that variables (and functions) will persist from script invokation to invokation. If you have two scripts that run in #targetengine session, for instance, because of their user interfaces, they can have conficting global variables. (Some people will suggest you should give each script its own #targetengine. I am not convinced this is a good idea, but my reasons against it are mostly speculation about performance and memory issues, which are things I will later tell you to not worry about.)
    But I think you've answered one of my questions when you say that the
    thing to avoid is the "v1" scope. Although I don't really see what the
    problem is in the context of InDesign scripting (unless someone else is
    going to using your script as function in one of theirs). Probably in
    Web design it's more of an issue, because a web page could be running
    several scripts at the same time?
    It's more of an issue in web browsers, certainly (which I have ~no experience writing complex Javascript for, by the way), but it matters in ID, too. See above. It also complicates code reuse across projects.
    Regarding functions altering variables: for example, I have a catalog
    script. myMasterPage is a variable that keeps track of which masterpage
    is being used. A function addPage() will add a page, but will need to
    update myMasterPage because many other functions in the script refer to
    that. However, addPage() also needs to update the total page count
    variable, the database-line-number-index-variable and several others,
    which are all used in most other functions. It seems laborious and
    unnecessary to pass them all to each function, then have the function
    alter them and return an array that would then need to be deciphered and
    applied back to the main variables. So in such a case I let the function
    alter these "global" (though not v1) variables. You're saying that's okay.
    Yes, that is OK. It's not a good idea to call that scope "global," though, since you'll promote confusion. You could call it...outer function scope, maybe? Not sure; that assumes addPage() is nested within some other function whose scope is containing myMasterPage.
    It is definitely true that you should not individually pass them to the function and return them as an array and reassign them to the outer function's variables.
    I think it is OK for addPage() to change them, yes.
    Another approach would be something like:
    (function() {
      var MPstate = {
        totalPages: 0,
        dbline: -1
      function addPage(state) {
        state.totalPages++;
        state.dbline=0;
        return state;
      MPstate = addPage(MPstate);
    I don't think this is a particularly good approach, though. It is clunky and also doesn't permit an easy way for addPage() to return success or failure.
    Of course it could instead do something like:
        return { success: true, state: state };
      var returnVal = addPage(MPstate);
      if (returnVal.success) { MPstate = returnVal.state; }
    but that's not very comforting either. Letting addPage() access it's parent functions variables works much much better, as you surmised.
    However, the down-side is that intuitively I feel this makes the script
    more "messy" -- less legible and professional. (On the other hand, I
    recall reading that passing a lot of variables to functions comes with a
    performance penalty.)
    I think that as long as you sufficiently clearly comment your code it is fine.
    Remember this sort of thing is part-and-parcel for a language that has classes and method functions inside those classes (e.g. Java, Python, ActionScript3, C++, etc.). It's totally reasonable for a class to define a bunch of variables that are scoped to that class and then implement a bunch of methods to modify those class variables. You should not sweat it.
    Passing lots of variables to functions does not incur any meaningful performance penalty at the level you should be worrying about. Premature optimization is almost always a bad idea. On the other hand, you should avoid doing so for a different reason -- it is hard to read and confusing to remember when the number of arguments to something is more than three or so. For instance, compare:
    addPage("iv", 3, "The rain in spain", 4, loremIpsumText);
    addPage({ name: "iv", insertAfter: 3, headingText: "The rain in spain",
      numberColumns: 4, bodyText: loremIpsumText});
    The latter is more verbose, but immensely more readable. And the order of parameters no longer matters.
    You should, in general, use Objects in this way when the number of parameters exceeds about three.
    I knew a function could return an array. I'll have to read up on it
    returing an object. (I mean, I guess I intuitively knew that too -- I'm
    sure I've had functions return textFrames or what-have-you),
    Remember that in Javascript, when we say Object we mean something like an associative array or dictionary in other languages. An arbitrary set of name/value pairs. This is confusing because it also means other kinds of objects, like DOM objects (textFrames, etc.), which are technically Javascript Objects too, because everything inherits from Object.prototype. But...that's not what I mean.
    So yes, read up on Objects. They are incredibly handy.

  • Code 91 - Caused Error: (Object variable or With block variable not set)

    Hi,
    We are using FDM 9.3.1. We have enabled batch processing.
    We are having following process being followed
    - Batch Loader script will pull the data from dwh table for each entity, scenario, year and period
    - Batch processing is set to serial and processlevel set to Up-To-Check
    - We had following five files created for Location - EMAFF100
    i. 1_EMAFF100_ACT_May-2011_RR.txt
    ii. 1_EMAFF100_ACT_Jun-2011_RR.txt
    iii. 1_EMAFF100_ACT_Jul-2011_RR.txt
    iv. 1_EMAFF100_ACT_Aug-2011_RR.txt
    v. 1_EMAFF100_ACT_Sep-2011_RR.txt
    Batch loader process completed the processing for May - 2011, Jul - 2011, Aug-2011, Sep-2011.
    But for Jun 2011 it has given the following error in the 'tbatchinformation' table and failed at import stage.
    40751.6239236111 1_EMAFF100_ACT_JUN-2011_RR.TXT 2 2 91-Object variable or With block variable not set
    When we checked the view error log from tool menu we found following
    ** Begin FDM Runtime Error Log Entry [2011-07-27-14:58:29] **
    ERROR:
    Code......................................... 91
    Description.................................. File [1_EMAFF100_ACT_Jun-2011_RR.txt] Caused Error: (Object variable or With block variable not set)
    Procedure.................................... clsBatchLoader.mFileCollectionProcess
    Component.................................... upsWBatchLoaderDM
    Version...................................... 931
    Thread....................................... 5600
    IDENTIFICATION:
    User......................................... ncreighton
    Computer Name................................ HYAPSDEV1
    App Name..................................... EMATTEST
    Client App................................... WebClient
    CONNECTION:
    Provider..................................... ORAOLEDB.ORACLE
    Data Server..................................
    Database Name................................ hydev_serv
    Trusted Connect.............................. False
    Connect Status.. Connection Open
    GLOBALS:
    Location..................................... EMAFF100
    Location ID.................................. 762
    Location Seg................................. 16
    Category..................................... ACT
    Category ID.................................. 13
    Period....................................... Jun - 2011
    Period ID.................................... 30/06/2011
    POV Local.................................... False
    Language..................................... 1033
    User Level................................... 1
    All Partitions............................... False
    Is Auditor................................... False
    We then re submitted data for Jun period and saw batch process got successfully completed and June data got imported successfully and also rest other processes got through.
    Can any one provide exact cause for this error? As we have automated the data load from DWH to FDM And then to HFM. Hence when such error comes it disturbs lot of processing there on. Appreciate your early response.
    Thanks in advance.

    Hi SAP collegues,
    At my site, BPC Excel created this problem too "Object Variable or With Block Variable not set" .
    It turned out that this is symptom of a a dys-functioning BPC COM Plug-in in XL2007 or XL2010!
    This is a consequence that your Excel recently crashed while using BPC. And it relates to an Excel Add-in becoming disabled when the applications crashes.  Please check the following.
    Note before doing the following, close all other open Excel and BPC sessions.
    Within Excel go to File à Options
    Select the Add-Ins option on the left
    Select the <<COM Add-ins >> option in the Manage drop down, and click Go
    Make sure that the Planning and Consolidation option is selected.  If not, mark this box and click OK.
    If you do not see anything listed, return to the Add-in screen and select the Disabled Items option, and see if Planning and Consolidation is listed there.
    Let me know if you have any queries,
    Kind Regards,
    robert ten bosch

  • Variable Scope at package or interface level

    Hi,
    Can we set the ODI Project variable scope to package or interface level
    because in my project im using a last rundate refresh variable this variable value will be changed at the time of execution of each package.
    Thanxs
    Madhavi

    you can create it as "Not Persistent" and then its value exist per ODI session.
    In this way, several sessions can keep independent value to the same variable.

  • Exported Final Cut XML from Imovie09 causes loss of Audio Sync

    I have recently upgraded to ILife09 and tried a process that always worked in ILife08 but now get Audio Sync problems.
    I have created an Imovie project that is 2hours and 50 mins long and wanted to export it to Final Cut Express as XML. This used to work 100% with Imovie08. However, with this latest version of Imovie, when exported to Final Cut Express, the first 45 mins of the XML movie is well out of sync (Audio / Visual).
    Has anyone experienced this?

    Hi Roberic,
    there is a bug in iMovie '09 that causes loss of audio sync when you use custom slow/fast motion. This has been experienced by many users. See for example this thread:
    http://discussions.apple.com/thread.jspa?messageID=9152271
    I don't know if this applies to exports to .xml but it could well be that your problem lies here. There are some workarounds, being the easiest one to only use what the slow motion slider snaps to instead of entering custom speed percentages.

  • Upgrade XF86 causes loss of X and Kde(solved)

    Upgrade this day caused loss of X and KDE.
    Reference made to shared libx11 not opened.
    Side issue:  Knoppix cannot access internet in version 3.4 or version 3.7 on the affected machine.
    Virus?

    Startx message:  error while loading shared libraries:libx11.so.6 : cannot open shared object file:  no such file or directory.

  • Cfm template updating cfc variable scope

    Don't know if anybody's run into this before, but I ran into a strange issue with the variable scope in a cfc.  Basically, I have some application settings stored in a database table, and then I have a cfc saved to application scope in which I store the contents of the table in a variable scope query.  Within the cfc, I have a getter function that preforms a query of queries to pull the data I need.  I then have an admin screen within the application to update the settings.
    This is (very generally) what my cfc looks like:
    <cfcomponent  name="settings.cfc">
         <cffunction name="init" returntype="settings">  
              <cfset setAppSettings() />  
              <cfreturn this />  
         </cffunction>  
         <cffunction name="setAppSettings">  
              <cfquery name="variables.qrySettings" datasource="#application.dsn#">  
                   SELECT *
                   FROM SETTINGS
              </cfquery>  
         </cffunction>  
         <cffunction name="getAppSettings" returntype="query">  
              <cfargument name="id" />
              <cfset var local = structNew() />  
              <cfquery name="local.qryResult" dbtype="query">  
                   SELECT *
                   FROM variables.qrySettings
                   WHERE ID = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_numeric" />  
              </cfquery>  
              <cfreturn local.qryResult />  
         </cffunction>  
    </cfcomponent>
    In onApplicationStart in Application.cfc, I have this line:
    <cfset  
    application.objSettings = createObject("component","settings").init() />

    Sorry, accidentally posted before I was done...
    Basically, the problem is that I have an admin screen that updates the settings.  I call the getter function in a cfm template, and I save the result to a variable called variables.qrySettings (same name as in the cfc) like this - <cfset variables.qrySettings = application.objSettings.getAppSettings(url.id) />.  For some reason, this seems to overwrite variables.qrySettings in the cfc.  Any ideas????

  • Variable scope within an interface and some questions

    I am creating a DataStorage interface with a member variable (can I call it a member variable when it is in an interface?) called dataObject. From what I remember, and what the compiler is telling me, the scope declarations "private," or "protected" can not be used on either methods or member variables in an interface.
    Now I have another class DataInput that implements DataStorage and I want to make the dataObject private and put in accessor methods to get to the dataObject. But I also remember reading something that said, during inheritance you can not make the scope of the method (and variable?) more narrow. Meaning if a method was defined as default in the parent class, the subclass can not override that method to give it private access all of a sudden.
    Now a couple of questions with this...does that rule only apply to subclassing (that is with extends) or does it also apply to implementing interfaces. Second question, I am pretty sure that rule applies to methods that are being overriden, but does it also apply to variables in an interface...because if that is the case, I can't re-declare the variable in the class that implements the interface to be private...and then there is no way to protect that variable.
    By the way I did re-declare the variable in the subclass (implementing class) and declared it as a private, and it works...but I'm still trying to figure out the general rule.

    well if the interface variables are implicitly public static final, how come I am able to re-declare the variable name within the class that implemented the interface.
    If for example in interface Car there is a variable color, how come in class Honda implements Car, I can redeclare the variable color, and give it public access. I thought final meant final, no redeclaring...but does that not hold for static variables?

  • Redirection causes loss of param/attribute values

    Hello I am new to JSF and I have a few questions regarding the same .
    I am using (JSf-struts) for a web application in which I redirect a page (in the config class) .I am not able to access param/attribute values in the action class after redirection.
    Does redirection cause the loss of param values , if so what should be the remidy.
    If I want add an attribute (with session scope) how do I add it in the JSF
    can I do something like this ....
    <f:param name="datasets" scope="session" value="Master.txt" />

    Put in session
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key,
                                                                                       obj);

  • Operating system causes loss of data during writing to file continuously

    Within a while loop I read data from serial port (9,5KByte/sec, bluetooth dongle via serial port protocol) and writes them to a file (text-file) continuously. The operating system interrupts the while loop periodically which causes a loss of data. If I read data from serial port without saving them no data get lost.
    E.g. on my PC the OS (W2K) wakes up a second hard disk exactly once per hour which freezes the data saving process to the 'saving' hard disk (and therefore also the while loop, data reading) for about 5-6 sec. On a Laptop the OS (XP, one single hard disk) interrupts the data saving process every 10 minutes for about 1 sec. during the first hour and not any longer afterwards.
    I have al
    so tried to use the 'deny read/write' option of the 'Open File.vi' to prevent other file sweeping applications (backup, anti-virus, Fast Find) to open the file simultaneously which could temporarily deny you write access to the file - no success.
    BTW, this concerns also the compiled version of my LV7.1-program.
    Any suggestions?
    Thanks,
    Tobi

    Use two loops, one for reading the serial data and a separate one for writng to the file. The first loop reads the serial port and writes the data to a queue. The second one reads the queue and writes to the file. Put a delay in each loop, perhaps zero milliseconds in the serial loop and 10 ms in the file loop (try various values). This causes the LV scheduler to share CPU time between the two loops.
    Now the serial loop will acquire the data and store it in the queue which also serves as a buffer. If the file loop gets blocked by the OS, the data just stacks up in the queue.
    Lynn

  • Exception caused by bind variables in ORDER BY clause and VO RANGE_PAGING

    Hi,
    I'm using a ViewObject in RANGE_PAGING mode and discovered a problem when using bind variables in the ORDER BY clause of my statement:
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3 When a bind variable is used in the ORDER BY CLAUSE and the method VO.getEstimatedRowCount() is call then the DB issued an SQL error:
    java.sql.SQLException: Ungültiger Spaltenindex (eng.: invalid column index)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:137)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:174)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:239)
         at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4612)The numbering of the bind variables indicates that the last two bind variables have the wrong numbering (??)
    When I rewrite the SQL into the following statement, the SQL error does not occur but I have not verified yet that the VO delivers the correct range of data because the numbering of the bind variables is not correct.
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT *, decode (attr2, :1, 1, null, 0, -1) as ATTR_FOR_SORTING FROM T_TABLE WHERE (attr1 = :2) ORDER BY ATTR_FOR_SORTING  desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3I'm working with JDev 10.1.2 and Oracle DB 9203.
    Any comments are welcome!
    Thanks,
    Markus

    You are using the bind variable :2 twice. Did you try
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :4) WHERE Z_R_N > :3
    setWhereClauseParm(0, "a"); // :1
    setWhereClauseParm(1, "b"); // :2
    setWhereClauseParm(2, "c"); // :3
    setWhereClauseParm(3, "b"); // :2setting the fourth parameter the same as the second one?
    I remeber reading something about using bind variables twice causing problems, but I#m not sure about it.

  • Why is variable scope so vexing?!  Argh!

    Dear Friends
    I used to think that if I declared a variable at the top of
    the first frame of my main timeline (and outside of any function
    bodies) that it would basically be considered "global" and could be
    accessed at any further frame in the main timeline (and by any
    child of the main timeline via prefixing enough "parent."s) but
    this is apparently not the case (unless there's something funny
    with uints where their values go to 0 from one frame to the next.)
    Is there something I'm missing here? Why is it so hard to declare a
    variable that can be easily seen throughout the main timeline (and
    the rest of the app as well)?
    And speaking of children seeing their parent's variables,
    what is the easiest way to make a variable declared on the main
    timeline accessible inside of a child? I don't want to have to
    count ancestors and add "parent.parent.parent." etc. and "root."
    doesn't seem to work... What's the magic prefix? Isn't there also a
    way of setting a variable equal to "this" on the main timeline? I
    don't know how it works, really.
    More generally speaking, does anyone have a surefire tutorial
    on variable scoping? I've read Moock and pored over the Help manual
    and it all still feels a lot less intuitive than it ought to. How
    do I master this subject?!
    Thanks and Be Well,
    Graham

    graham - you're right in saying that a var on the main
    timeline can be considered 'global' even without the use of a
    '_global' keyword - and i remember in my early learning i
    definitely thought the same thing as you are now. It's really a
    matter of 'paths' as you mention, but one does need to 'point' to
    the main in order to retrieve the value via root or a series of
    parents - even when using class structures as is more common now
    under 3, one still needs to point at the correct scope to access a
    property.
    sometimes though, a var can be 'reset' ... what i mean by
    this is, say for instance you have declared a var on the first
    frame, the playhead then navigates to a different frame wherein the
    variable has been set to a different value, then at another time
    the playhead returns to frame one (because one has a navigation
    structure that does so) in this case the variable is 're-declared'
    and set back to the default value! this type of situation often
    occurs with a timeline based system.
    class properties on the other hand, cannot be reset in this
    manner, which is one of the many reasons why class based systems
    are better for complex programming. personally, now-a-days my
    programs so not usually contain anything on the main timeline, no
    code or assets, instead all operations are achieved through code,
    mainly within class files (as is the benefit of 3)
    I'm sorry i don't know of any tuts i could point you to, just
    stick with it - i think that over time it hierarchy structure and
    path scopes become second nature - and at the rate you seem to be
    advancing, it shouldn't take long ;)

  • Variable scope with loaded external SWF's?

    I’ve got an SWF, call it calcLite, that will be deployed both independently (ie: attached to an HTML doc) and also imported at run time (linked as an external asset via the loader class) to another SWF, let’s call it calcPro. That part is working fine.
    I’ve got a global variable, gRunMode:String that calcLite must declare and set when it’s running independently, but must inherit when attached to calcPro (which will declare and set gRunMode before attaching calcLite).
    Here’s where I am:
    At the root of calcPro:
    var gRunMode:String = “touchScreen”;
    At the root of calcLite:
    var gRunMode:String = “web”
    if (this.parent == this.stage) {
         gRunMode = MovieClip(this.parent.parent.parent).gRunMode;
    I’ve also tried creating function in the parent to return gRunMode:
    At the root of calcPro:
    var gRunMode:String = “touchScreen”;
    function getRunMode():String {
         return gRunMode;
    At the root of calcLite:
    var gRunMode:String = “web”
    if (this.parent == this.stage) {
         gRunMode = MovieClip(this.parent.parent.parent). getRunMode();
    I’ve also tried the second technique, renaming the global in calcPro to gRunModeExe incase there was a naming violation. In all cases I get “attempt to access prop of a null” error. The construct MovieClip(this.parent.parent.parent).function() works, I use it later in the program for a different function and it’s fine, just doesn’t work here.

    My bad, I wrote the post from memory at home. My actual code properly tested the stage (!=) and would have worked EXCEPT under the following condition:
    This is my second project in a row that involved an SWF that must operate independently and also function as a loaded child to a bigger project. What I keep forgetting is that loaded content begins to execute IMMEDIATELY!!!, it does not wait to be attached to the stage. Further, loaded content does not have access to stage assets until it’s been attached, so any premature attempts to access global variables and functions from loaded clip to stage fail. A good explanation of these issues can be found here (scroll to middle of page, post by senocular titled Access to stage and root): http://www.kirupa.com/forum/showthread.php?p=1955201
    The solution was simple enough. If calcLite is running as a child, stop in frame 1 (before any other processing) and wait for calcPro to push us to the next frame (which happens after attachment to the stage). If calcLite is running independently skip the stop and proceed as normal.
    As for this.parent.parent.parent vs. this.parent.parent vs this.parent, since gRunMode is global within the calcPro scope any of these would probably work (although I’ve only tested the first option). The first parent references the loader object, the second parent references the movie clip to which the loader object is attached, and the third parent finally references root.

  • Having Truble Reading and Echoing Using PHP in HTML. Possible Variable Scope Problem?

    Hey guys,
       Thanks for your always knowledgable help! Today I am working with displaying text from a text file in an HTML table using PHP. I can't get the data to display properly, I think it has something to do with the scope of the variables, but I am not sure. Here is the code I am struggeling with:
    <table width="357" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td width="165">Pizza 1</td>
        <td width="186"><? echo  $price['0']; ?></td>
      </tr>
      <tr>
        <td>Burger 1</td>
        <td><? echo $price['1']; ?></td>
      </tr>
      <tr>
        <td>Drink 1</td>
        <td><? echo $price['2']; ?></td>
      </tr>
    </table>
    In the above PHP (not shown) the array $price is filled properly (I tested by echoing each bit line by line) but by the time we get into the HTML it seems the array is empty or it is not liking how I am calling it. Does the scope of a PHP variable end with the closing "?>" tag? Am I missing something? Bellow is the full code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body {
        background-color: #333;
        color: #FFF;
    </style>
    </head>
    <body>
    <?php
    $menu=fopen("prices.txt","r") or exit("Unable to open file!");
    $price=array();
    $priceposition=null;
    $tempstring;
    //This loop does all of the READING and populating of variables
    while(!feof($menu))
        //Check to see if this is the first pass, if not add one to the array possition
        if ($priceposition==null){
            $priceposition=0;
        else{
        $priceposition++;
        //populate the temparary string
        $tempstring = fgets($menu);
        //Populate the array if the temporary string is not a comment
        if(substr($tempstring,0,2) != "//"){
            $price['$priceposition']= $tempstring;
            echo $price['$priceposition'];
      //End of reading loop
    fclose($menu);
    ?>
    <table width="357" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td width="165">Pizza 1</td>
        <td width="186"><? echo  $price['0']; ?></td>
      </tr>
      <tr>
        <td>Burger 1</td>
        <td><? echo $price['1']; ?></td>
      </tr>
      <tr>
        <td>Drink 1</td>
        <td><? echo $price['2']; ?></td>
      </tr>
    </table>
    </body>
    </html>
    and you can run the code on my test server here: christianstest.info/phptest/readwritetesting/readtest.php
    thanks guys!

    MurraySummers wrote:
    Try changing this -
    fclose($menu);
    to this -
    fclose($menu);
    echo "<pre>";exit(print_r($price));
    and see what you get.
    Wow, what a great little peice of testing code, thanks! That showed me the problem right away! Is there any way to test your php line by line in Dreamweaver CS6? I am used to computer programing in Visual Studio and Eclipse where they have an option of running code line by line and seing how variables populate and change with each line of code execution. Or is thier a program that can do this for PHP?

  • Variable scope in plsql package

    When I run the following package, proc2 is always printing the value of i = 1 even though proc1 is incrementing the value of i correctly? Could any one explain to me what is the problem with this code?
    CREATE OR REPLACE PACKAGE test_pkg
    is
    PROCEDURE proc1 (p_fetch_limit in number := 200);
    PROCEDURE proc2 (rec_id out number);
    END test_pkg;
    CREATE OR REPLACE PACKAGE BODY test_pkg
    IS
    cursor test_cur
    IS
    select new_app,
    card_number,
    process_flag,
    process_date,
    seq_number
    from wm_opt_scan_temp
    where process_flag = 'N' and process_date IS null
    and new_app = 'Y'
    order by seq_number;
    type test_cur_type IS table of test_cur%rowtype;
    cur_rec test_cur_type;
    i number := 1;
    l_rec_id number := 0;
    -- PROC1 --
    PROCEDURE proc1 (p_fetch_limit in number := 200)
    IS
    BEGIN
    open test_cur;
    loop
    fetch test_cur bulk collect into cur_rec limit p_fetch_limit;
    exit WHEN cur_rec.count = 0;
    for i in 1..cur_rec.count
    loop
    DBMS_OUTPUT.put_line('proc1 - i<'||i||'> seq#<'||cur_rec(i).seq_number||'> card#<'||cur_rec(i).card_number||'>');
    l_rec_id := 0;
    proc2(l_rec_id);
    END loop;
    END loop;
    CLOSE test_cur;
    COMMIT;
    DBMS_OUTPUT.put_line('proc1 procedure finished...');
    END proc1;
    -- PROC2 --
    PROCEDURE proc2 (rec_id out number)
    IS
    BEGIN
    DBMS_OUTPUT.put_line('proc2 started - i<'||i||'> seq#<'||cur_rec(i).seq_number||'> card#<'||cur_rec(i).card_number||'>');
    END proc2;
    END test_pkg;
    output is:
    Connecting to the database Test.
    proc1 - i<1> seq#<7841> card#<40992814376>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<2> seq#<8041> card#<40992779256>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<3> seq#<8241> card#<40992745696>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<4> seq#<12681> card#<40992814376>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<5> seq#<12682> card#<40992814375>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<6> seq#<12683> card#<40992814378>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<7> seq#<12684> card#<40992814379>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<8> seq#<12685> card#<40992745756>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<9> seq#<12686> card#<40992745757>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<10> seq#<12689> card#<40992814377>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<11> seq#<12690> card#<40992745755>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<12> seq#<12691> card#<40992745767>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<13> seq#<12692> card#<40992745771>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<14> seq#<12693> card#<40992745612>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<15> seq#<12694> card#<40992145673>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<16> seq#<12695> card#<40992745611>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<17> seq#<12697> card#<40992745661>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<18> seq#<12698> card#<40992745689>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 - i<19> seq#<12700> card#<40992745771>
    proc2 started - i<1> seq#<7841> card#<40992814376>
    proc1 procedure finished...
    Process exited.
    Disconnecting from the database Test.

    Assign it to a separate global variable, and don't name it "i" so that the global variable is visible within the for loop.
    As for Java, consider the following:
    public class Foo {
    private int i;
    public void proc1() {
    for (int i=0;i<10;i++) {
    // do stuff
    public void proc2() {
    System.out.println("i = "+i);
    Same problem: two variables in different scopes, both named "i".

Maybe you are looking for

  • Recieving an error message

    I recieve this error message when I open iCal on my MacBook. I am new to using iCal so I have no idea why I'm getting this message and how to get rid of it. It says: The server responded with an error Access to account "[email protected]" is not perm

  • Missing Tool Palette

    Really feel silly asking but . . . Just upgraded to CS 5.5 from CS3. Can't seem to find the tool palette (slection arrows, type tool, etc.)

  • Can't see which Facebook friends have Skype

    I have the latest version of Skype for Desktop and whenever I select 'Find Facebook friends' the Home Page doesn't show me the list of friends who have Skype.

  • How to use more than one JVM's

    hi friends, if there are two javas i.e. 1.3 and 6 installed on my machine and I am using Java 6 for my IDE and 1.3 as default. Now after building an application if i distribute it to other pc's that are using java 1.3 as default and does nt have java

  • Why do we create custome EventQueue?

    I see applications creating own custom EventQueues. Toolkit.getDefaultToolkit().getSystemEventQueue().push(customEventQueue); Why do we create our own eventqueues? Please explain. I was not able to find much documentation on java tutorial. thanks vin