Jump to content

danludwig

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

danludwig's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The link I gave you was from the TinyMCE download page, http://tinymce.moxiecode.com/download.php. The software is mostly client-side javascript that runs in the browser, but the spellcheck does a server-side call, and in turn the server uses either PSpell, ASpell, or Google Spellcheck service. I totally hear you on the gimpiness. I found this comment in the Moxiecode JSON.php file: "This method was needed since PHP is crapy and doesn't have pointers/references". The funnniest part is that they misspelled crappy! Anyway, this is why I abandoned PHP and MySQL 6 years ago, I was tired of waiting for them to become fully-featured OO language / RDBMS. Since you say you know a little C#, I'm going to upload the classes I've been working on. These are my attempts to recode the 2 classes in the JSON.php file. The classes can be tested and debugged like so: public void TestJsonParser() { string sampleJsonRequest = "{\"id\":\"c0\",\"method\":\"checkWords\",\"params\":[\"en\",[\"Here\",\"is\",\"some\",\"text\",\"I\",\"want\",\"to\",\"spellcheck\"]]}"; // this is a JSON request as the server receives it from TinyMCE JsonGraph graph = new JsonGraph(); object jsonData = graph.Decode(sampleJsonRequest); } So far, the JsonReader seems to be working except that it was throwing OutOfRange exceptions when it gets to the end of the string it's parsing. The JsonGraph also seems to be working, sorta, but I'm confused about the data objects it's creating. I probably did something wrong, and it's probably due to my misunderstanding of how PHP is using arrays to construct the objects. [attachment deleted by admin]
  2. Yes, this is preexisting code. I was just thinking maybe I should post asking for people to collaborate with me on what I'm doing than posting 1001 PHP questions. What I am doing is creating an adapter for the Moxiecode TinyMCE spellchecker plugin, so that it can consume a .NET spellchecking service instead of a PHP spellchecking service. I plan to contribute my source back to Moxiecode, and to anyone interested in collaborating feel free to let me know. As for the source, I don't know if I can actually upload it or post it here, but it is open source. You can download the files I'm trying to decipher from http://sourceforge.net/projects/tinymce/files/TinyMCE%20Spellchecker%20PHP/2.0.2/tinymce_spellchecker_php_2_0_2.zip/download. The files I have open right now are config.php, rpc.php, and JSON.php. The first 2 are in the root directory of the download, the third is in the classes/utils folder. The source I've mentioned here is based on code from the JSON.php file, mainly in the decode readValue method of the Moxiecode_JSON class. By the way, sorry about not being clear in the first question. Yes, I meant that $this points to an instance of a class (object), not the class itself. I am an OO developer, but I'm used to more strongly-typed constructs like those in Java and C#. Haven't coded PHP since about 2003. Thanks for the 2 answers. Do I move on to round 3 now?
  3. Hi, I am trying to decipher some OO PHP code, and don't have PHP environment to test in. I've had some experience with PHP years ago, but very little of it was using OO PHP. If anyone could help answer any of the following questions for me, I'd appreciate it. 1.) From what I remember, the $this variable refers to the class calling a method or field, using the syntax $this->_someField or $this->someMethod. What does it mean if a $this field reference is expressed in a method, without declaring it in the actual containing class? For example: class MyPhpClass { function myMethod() { $this->variable1 = array(); $this->variable2 = array(); $methodLocalVariable1 = null; $methodLocalVariable2 = 30; } } The class fields variable1 and variable2 are not declared in the class (i.e. there is no "var $variable1, $variable2;" line). Does expressing them in the method atuomatically declare them for use by the entire class? In other words, is this a shortcut for using class-scoped fields without declaring them explicitly outside of the method body? 2.) I have actually read the PHP Manual regarding this next question, but I'm still confused. Say I have the following in a method: $this->array1 = array(); $this->array2 = array(); $this->currentArray =& $this->array1; Does the use of the amphersand (&) after the assignment operator (=) ensure that I'm storing a reference to $this->array1 rather than a separate copy of it? In other words, what would be different if I removed the amphersand and just had the line "$this->currentArray = $this->array1;" instead? If I modified $this->currentArray, would it modify $this->array1 as well? 3.) Continuing along the lines of question #2, consider the following: $this->array1 = array(); $this->array2 = array(); $this->currentArray =& $this->array1; while (reading and parsing a string) { if (some condition is met) { $currentArray =& $obj; } } In the above lines, $currentArray is not declared in a local scope -- only $this->currentArray is declared. Also, $obj is never declared or initialized. If there is no other use of either of these variables ($obj or $currentArray without the $this pointer), then what in the world does this line of code do? I've searched the entire class' source code, and this line is the only place where either of these variables is used. Thanks in advance for your help. Dan
  4. Thanks everyone for the quick replies. I was confused because the code I'm looking at does in fact initialize a variable $key = null; then soon afterward assigns a value using $someArray[$key] = $someOtherVariable. I vaguely remembered from my PHP days that the brackets were a shortcut for adding to the end of an array, but wanted to make sure that this wasn't a shortcut to get the value stored under the NULL key. To confirm, if I create an array like so: $myArray = array(); $myArray["key1"] = "value1"; $myArray[] = "value2"; $myArray[1] = "value3"; $myArray[] = "value4"; ... then the corresponding keys of the array, in order, are "key1", 0, 1, 2. Right? I suppose my trick is going to be trying to figure out how to mimic a data structure like this in a more strongly-typed language. I was thinking Hashtable would work, but to add a value to one, you always have to specify a key. Guess I can just write a little helper method to auto-assign next int values and mimic an associative array. Thanks again.
  5. Hi, I don't have a PHP execution environment to test in, and am trying to read some PHP code to determine what it does. Say I declare a variable like so: $var = array(); If I remember correctly, I can put values into this array like so: $var["key1"] = "Some value"; $var[2] = "Some other value"; On the other hand, what does it mean if I do this? $var[] = "Some third value"; Does this stack the value onto the end of the array? If so, does it not have a key, or does it use NULL as a key? Also, in more strongly-typed languages, I'm used to managing keyed collections like this in objects like Hashtable (Java / CSharp / VB) rather than arrays. Hashtable in particular usually allows the use of NULL as a key once. Is it the same way in PHP? For example, if I have: $key = null; $array = array(); $array[$key] = "This is important information"; ...how would I access the important information? By calling $array[null] on the right side of an expression? Thanks, Dan
  6. From what you've posted, it looks like PHP will not return an error or -1, but will instead modify $someString by appending extra spaces to the end of it. For example: $someString = "Here is my string value."; $someIndex = 30; $someMutation = $someString[$someIndex]; In this case $someMutation would equal " " (empty space) and $someString would be changed to "Here is my string value. " (added spaces so that the string length is 31 characters and the index of 30 is valid). Is this right?
  7. Hi, It's been a long time since I've coded PHP. I am trying to rewrite some PHP code I found in a different language, and I have a question about treating strings as character arrays. For example, take the following PHP code: $someString = "Here is my string value."; $someIndex = 6; $someMutation = $someString[$someIndex]; With this code, I would assume that the value of $someMutation would be "s", since it is the character at the 6th position in the string (when starting from zero). However, what happens if the value of $someIndex was changed to 30, or 100, or ONE BILLION, or any index that is >= strlen($someString)? Does PHP return -1 in that case? Thanks for the help, I don't have a PHP execution environment to test in. Dan
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.